diff --git a/README.md b/README.md index 1383f94..c2dda79 100644 --- a/README.md +++ b/README.md @@ -4,5 +4,52 @@ +# 环境变量 + +| 环境变量 | 描述 | +| --- | --- | +| AEUS_DEBUG | 是否开启debug模式 | +| HTTP_PORT | http服务端口 | +| GRPC_PORT | grpc服务端口 | +| CLI_PORT | cli服务端口 | + + # 快速开始 +## 创建一个项目 + +创建项目可以使用`aeus`命令行工具进行生成: + +``` +aeus new github.com/your-username/your-project-name +``` + +如果需要创建一个带管理后台的应用, 可以使用`--admin`参数: + +``` +aeus new github.com/your-username/your-project-name --admin +``` + + +## 生成`Proto`文件 + +服务使用`proto3`作为通信协议,因此需要生成`Proto`文件。 + +``` +make proto +``` + +清理生成的文件使用: + +``` +make proto-clean +``` + +## 编译项目 + +编译项目可以使用`make`命令进行编译: + +``` +make build +``` + diff --git a/app.go b/app.go index 51e9c95..c82a87b 100644 --- a/app.go +++ b/app.go @@ -122,7 +122,7 @@ func (s *Service) injectVars(v any) { } func (s *Service) preStart(ctx context.Context) (err error) { - s.Logger().Info(s.ctx, "starting") + s.Logger().Info(ctx, "starting") for _, ptr := range s.opts.servers { s.refValues = append(s.refValues, reflect.ValueOf(ptr)) } diff --git a/middleware/auth/jwt.go b/middleware/auth/jwt.go index fddf9b2..b49ba0d 100644 --- a/middleware/auth/jwt.go +++ b/middleware/auth/jwt.go @@ -47,7 +47,13 @@ func WithAllow(paths ...string) Option { if o.allows == nil { o.allows = make([]string, 0, 16) } - o.allows = append(o.allows, paths...) + for _, s := range paths { + s = strings.TrimSpace(s) + if len(s) == 0 { + continue + } + o.allows = append(o.allows, s) + } } } @@ -65,19 +71,19 @@ func WithValidate(fn Validate) Option { // isAllowed check if the path is allowed func isAllowed(uripath string, allows []string) bool { - for _, str := range allows { - n := len(str) - if n == 0 { - continue + for _, pattern := range allows { + n := len(pattern) + if pattern == uripath { + return true } - if n > 1 && str[n-1] == '*' { - if strings.HasPrefix(uripath, str[:n-1]) { + if pattern == "*" { + return true + } + if n > 1 && pattern[n-1] == '*' { + if strings.HasPrefix(uripath, pattern[:n-1]) { return true } } - if str == uripath { - return true - } } return false }