1 Star 0 Fork 1

ApulisPlatform / ad-hub-bff

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

ad-hub-bff

  • BFF means "Backends for Frontends"
  • 仅针对普通HTTP请求。sse/websocket/文件流等请求由其他服务管理

接口种类

  1. 直接转发,可使用internal/routers/redirect_utils.go直接转发
  2. http请求原子服务,使用internal/httpclient/client.go进行请求
  3. 有些业务是异步处理的,需要监听rabbitmq,处理对应逻辑

项目结构说明

整体目录结构

参考文档Standard Go Project Layout

  • cmd/: 项目入口,main函数。
  • internal/: 业务代码。internal为不需要被外部repo调用的代码,聚合层几乎都是业务逻辑,无需被外部引用。
  • deps/: 本地依赖包。非公共仓库的。放在vendor文件夹执行go mod vendor会丢失文件,故放到不被go直接管理的文件夹下
  • api/: openapi/swagger文档文件
  • docs/: 项目设计文档
  • configs/: config-template或默认config文件
  • build/: 构建代码,如Dockerfile
  • deployments/: 部署代码,如k8s yaml等

文件

  • go.mod, go.sum: golang依赖管理代码
  • Makefile: 常用命令
  • .gitmodules: git submodule定义,通过git submodule add自动生成

internal目录结构

  • configs: 应用配置文件映射结构体
  • daos:调用数据库逻辑代码
  • database: 数据库驱动相关代码
  • middlewares:中间件,如auth等
  • models:数据库结构体定义
  • requests:请求结构体定义
  • responses:响应结构体定义
  • routers:路由管理
  • services:应用逻辑函数

生成swagger文档

  1. 确保当前环境swag命令可以使用
    • 安装swag命令go get -u github.com/swaggo/swag/cmd/swag
    • $GOPATH/bin添加到PATH
  2. 生成文档到api文件夹
    • swag init -g cmd/api_server.go -o api
  3. 运行项目是查看swagger文档
    • go run cmd/api_server.go
    • 打开浏览器到http://<HOST>:<PORT>/swagger/index.html找到API文档
  4. 导入到Yapi
    • 将步骤2生成在api/文件夹下的内容导入yapi

git submodule管理

apulis代码日常托管在自建gitlab, 但部分代码可能开源至github,故mod命名统一以github.com/apulis开头

添加

使用git submodule add命令

git submodule add git@apulis-gitlab.apulis.cn:sdk/simple-gin-logger.git deps/simple-gin-logger

go mod配置

在go.mod添加replace,用本地deps目录下的替换github.com/apulis相关依赖

replace github.com/apulis/simple-gin-logger v0.0.0 => ./deps/simple-gin-logger

如本地没load代码,下载代码

git submodule init
git submodule update

调试和运行项目

  1. 依照config.template.yaml编辑config.yaml文件
  2. 运行go run cmd/api_server.go

Makefile包含命令

  • get-deps: 加载submodule, 并把第三方依赖下载到本地vendor/文件夹下
  • vet-check-all: 使用go vet工具扫描代码(vet工具golang自带)
  • gosec-check-all: 使用gosec工具扫描代码(gosec工具go get github.com/securego/gosec/cmd/gosec)
  • build-api-server-bin: 构建二进制文件
  • build-api-server-docker: 构建docker
  • gen-swagger: 生成swagger文档
The MIT License (MIT) Copyright © 2021 <copyright holders> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

数据管理平台中间件 展开 收起
Go 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/apulisplatform/ad-hub-bff.git
git@gitee.com:apulisplatform/ad-hub-bff.git
apulisplatform
ad-hub-bff
ad-hub-bff
v1.6.0

搜索帮助