Skip to content

Commit

Permalink
add middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfzf committed Jul 28, 2022
1 parent 00b1a1c commit d001d44
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
13 changes: 11 additions & 2 deletions common/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,21 @@ func (s *SchemaApi) String() string {
@server(
prefix: v1/%s
group: %s
jwt: Auth
%s
%s
)`
jwt := ""
if s.pconf.Jwt {
jwt = "jwt:Auth"
}
middleware := ""
if len(s.pconf.Middleware) > 0 {
middleware = "middleware:" + strings.Join(s.pconf.Middleware, ",")
}

for _, tab := range s.Tables {
buf.WriteString("//--------------------------------" + tab.Comment + "--------------------------------")
buf.WriteString(fmt.Sprintf(temp, s.ServiceName, tab.TableName))
buf.WriteString(fmt.Sprintf(temp, s.ServiceName, tab.TableName, jwt, middleware))
buf.WriteString("\n")
buf.WriteString("service " + s.ServiceName + "-api{")
buf.WriteString("\n")
Expand Down
3 changes: 2 additions & 1 deletion common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ type ProtoConfig struct {
GoPackageName string `yaml:"goPackageName"`
OutFile string `yaml:"outFile"`
IgnoreTables []string `yaml:"ignoreTables"`

Jwt bool `yaml:"jwt"`
Middleware []string `yaml:"middleware"` //中间件
OnlySearch []string `yaml:"onlySearch"` //查询时出现,但增改时不会出现的字段,如id,created_at,updated_at
IgnoreColumns []string `yaml:"ignoreColumns"` //都不会出现的字段,如deleted_at,version

Expand Down
3 changes: 3 additions & 0 deletions yaml/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ tables:
- merchant_users
serviceName: merchant
outFile: merchant.api
jwt: false
middleware:
- CheckRole
ignoreColumns:
- deleted_at
- version
Expand Down

0 comments on commit d001d44

Please sign in to comment.