git clone https://github.com/waiter/pipi-gf-demo
ADDRESS | METHOD | ROUTE | HANDLER | MIDDLEWARE
----------|--------|----------------------|----------------------------------------------------------------------------|------------------------------
:8199 | ALL | /* | github.com/gogf/gf/v2/net/ghttp.internalMiddlewareServerTracing | GLOBAL MIDDLEWARE
----------|--------|----------------------|----------------------------------------------------------------------------|------------------------------
:8199 | ALL | /* | github.com/gogf/gf/v2/net/ghttp.MiddlewareHandlerResponse | GLOBAL MIDDLEWARE
----------|--------|----------------------|----------------------------------------------------------------------------|------------------------------
:8199 | ALL | /api.json | github.com/gogf/gf/v2/net/ghttp.(*Server).openapiSpec |
----------|--------|----------------------|----------------------------------------------------------------------------|------------------------------
:8199 | ALL | /swagger/* | github.com/gogf/gf/v2/net/ghttp.(*Server).swaggerUI | HOOK_BEFORE_SERVE
----------|--------|----------------------|----------------------------------------------------------------------------|------------------------------
:8199 | POST | /user/check-passport | pipi.com/gogf/pipi-gf-demo/internal/controller.(*cUser).CheckPassport | service.(*sMiddleware).Ctx
| | | | service.(*sMiddleware).CORS
----------|--------|----------------------|----------------------------------------------------------------------------|------------------------------
:8199 | POST | /user/is-signed-in | pipi.com/gogf/pipi-gf-demo/internal/controller.(*cUser).IsSignedIn | service.(*sMiddleware).Ctx
| | | | service.(*sMiddleware).CORS
----------|--------|----------------------|----------------------------------------------------------------------------|------------------------------
:8199 | GET | /user/profile | pipi.com/gogf/pipi-gf-demo/internal/controller.(*cUser).Profile | service.(*sMiddleware).Ctx
| | | | service.(*sMiddleware).CORS
| | | | service.(*sMiddleware).Auth
----------|--------|----------------------|----------------------------------------------------------------------------|------------------------------
:8199 | POST | /user/sign-in | pipi.com/gogf/pipi-gf-demo/internal/controller.(*cUser).SignIn | service.(*sMiddleware).Ctx
| | | | service.(*sMiddleware).CORS
----------|--------|----------------------|----------------------------------------------------------------------------|------------------------------
:8199 | POST | /user/sign-out | pipi.com/gogf/pipi-gf-demo/internal/controller.(*cUser).SignOut | service.(*sMiddleware).Ctx
| | | | service.(*sMiddleware).CORS
----------|--------|----------------------|----------------------------------------------------------------------------|------------------------------
:8199 | POST | /user/sign-up | pipi.com/gogf/pipi-gf-demo/internal/controller.(*cUser).SignUp | service.(*sMiddleware).Ctx
| | | | service.(*sMiddleware).CORS
----------|--------|----------------------|----------------------------------------------------------------------------|------------------------------
当前支持两种环境:
- 开发环境:
- 配置文件:
manifest/config/config.yaml
- 启动命令:
go run main.go
或者make dev
- 配置文件:
- 正式环境:
- 配置文件:
manifest/config/config.prod.yaml
- 启动命令:
go run main.go --gf.gcfg.file=config.prod.yaml
或者make prod
- 配置文件:
启动服务后,访问http://localhost:8199
即可,当前需要先创建一个用户名为pipi
,密码为123456
的帐号
- 当前需要前端每隔一定时间(比
internal/consts/consts.go
中定义的WebSocketHeartBeatTime
短即可)给服务端发送心跳包,直接发送内容为ping
的包即可 - 另外,所有前端发送的包(不只是心跳包)都会刷新后端记录本
WebSocket
的超时时间
前端给后端主要以JSON形式传递:
cmd
:本次命令类型data
: 本次携带数据
例如:
{"cmd":"testAdd","data":[1,78,3]}
后端回包格式与前端一致,会额外增加:
unique
:本WebSocket唯一IDpack
:服务端发出时间
例如
{"cmd":"add","data":82,"pack":1648906839,"unique":"ws-RFbD56T"}
另外,后端只需要在internal/service/socket/webLogic.go
中添加相关逻辑即可
启动服务后,到client
目录下go run .
即可启动简易的逻辑。另外,ClientSocket
的端口配置在config.yaml
中
其他设定与WebSocket
基本一致