- 友好而实用的日志记录方式
- 友好service调用方式
- go mod vendor
- go run entry/main.go
make set-config make set-dev-config
make docker-all
areaMap, err := app.MustGetAreaService().GetAreaMap(areaId)
if err != nil {
return c.BaseController.Fail(ctx, echoapp.Error_ArgumentError, "", err)
}
echoapp_util.ExtractEntry(ctx).Info(renderParams)
配置文件:
```
jws:
audience: "user"
issuer: "xytschool"
timeout: 360000
public_key_path: "./resources/keys/jws_public_key.pem"
private_key_path: "./resources/keys/jws_private_key.pem"
hash_ids_salt: "123456"
```
注意私钥只有在生成jws签名的模块或者服务需要加载
只做签名认证的服务或者只需加载公钥就可以,并且私钥的路径需要配置为空.
jwsMiddleware := echoapp_middlewares.NewJwsMiddlewares(middleware.DefaultSkipper, app.MustGetJwsHelper())
jwsAuth.Use(jwsMiddleware)
jws认证后可以使用 echoapp_util.GetCtxtUserId(ctx)获取用户id,想要获取用户完整信息需要配合user中间件,但是注意user中间件所在的服务需要有访问user数据库的权限,在一些微服务场景下我们往往只关心userId
userMiddleware := echoapp_middlewares.NewUserMiddlewares(middleware.DefaultSkipper, usrSvr)
authgoup.Use(userMiddleware)
func (sCtl *UserController) GetUserInfo(ctx echo.Context) error {
echoapp_util.ExtractEntry(ctx).Info("getUserInfo")
user, err := echoapp_util.GetCtxtUser(ctx)
if err != nil {
return sCtl.Fail(ctx, echoapp.Err_NotFound, "未发现用户", err)
}
return sCtl.Success(ctx, user)
}