Skip to content

Commit

Permalink
optimize: optimize tpl (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoranz758 authored Oct 18, 2023
1 parent 1db4904 commit e149312
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 56 deletions.
1 change: 1 addition & 0 deletions tpl/hertz/client/standard/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ layouts:
return defaultClient.{{$MethodInfo.Name}}(context, req, reqOpt...)
}
{{end}}
- path: hertz_client.go
body: |-
// Code generated by hz.
Expand Down
54 changes: 2 additions & 52 deletions tpl/hertz/server/standard/layout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ layouts:
if conf.GetConf().Hertz.EnablePprof {
pprof.Register(h)
}
// gzip
if conf.GetConf().Hertz.EnableGzip {
h.Use(gzip.Gzip(gzip.DefaultCompression))
Expand All @@ -75,7 +76,7 @@ layouts:
h.Use(recovery.Recovery())
// cores
h.Use(cors.Default())
h.Use(cors.Default())
}
- path: go.mod
Expand Down Expand Up @@ -368,7 +369,6 @@ layouts:
}
}
- path: biz/dal/redis/init.go
delims:
- ""
Expand Down Expand Up @@ -452,56 +452,6 @@ layouts:
sh build.sh
sh output/bootstrap.sh
```
- path: .gitignore
delims:
- ""
- ""
body: |-
*.o
*.a
*.so
_obj
_test
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.exe~
*.test
*.prof
*.rar
*.zip
*.gz
*.psd
*.bmd
*.cfg
*.pptx
*.log
*nohup.out
*settings.pyc
*.sublime-project
*.sublime-workspace
!.gitkeep
.DS_Store
/.idea
/.vscode
/output
*.local.yml
- path: .hz
delims:
- "{{"
- "}}"
body: |-
// Code generated by hz. DO NOT EDIT.
hz version: {{.hzVersion}},
- path: .gitignore
delims:
Expand Down
6 changes: 5 additions & 1 deletion tpl/hertz/server/standard/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ layouts:
"context"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/protocol/consts"
"github.com/cloudwego/hertz/pkg/protocol/consts"
{{- range $k, $v := .Imports}}
{{$k}} "{{$v.Package}}"
{{- end}}
Expand Down Expand Up @@ -59,6 +59,7 @@ layouts:
"{{$.ProjPackage}}/biz/service/{{$OutDir}}"
{{end}}
{{- end}}
- path: handler_single.go
body: |+
{{.Comment}}
Expand All @@ -83,6 +84,7 @@ layouts:
}
utils.SendSuccessResponse(ctx, c, consts.StatusOK, resp)
}
- path: "biz/service/{{.HandlerGenPath}}/{{ToSnakeCase .MethodName}}.go"
loop_method: true
update_behavior:
Expand Down Expand Up @@ -114,6 +116,7 @@ layouts:
// todo edit your code
return
}
- path: "biz/service/{{.HandlerGenPath}}/{{ToSnakeCase .MethodName}}_test.go"
loop_method: true
update_behavior:
Expand Down Expand Up @@ -141,6 +144,7 @@ layouts:
assert.DeepEqual(t, nil, err)
// todo edit your unit test.
}
- path: "{{.HandlerDir}}/{{.GenPackage}}/{{ToSnakeCase .ServiceName}}_test.go"
loop_service: true
update_behavior:
Expand Down
3 changes: 2 additions & 1 deletion tpl/kitex/client/standard/init_tpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ update_behavior:
body: |-
package {{ ReplaceString (ReplaceString .RealServiceName "." "_" -1) "/" "_" -1 }}
import (
"sync"
"github.com/cloudwego/kitex/client"
"github.com/cloudwego/kitex/pkg/transmeta"
"github.com/cloudwego/kitex/transport"
"sync"
)
var (
// todo edit custom config
Expand Down
1 change: 0 additions & 1 deletion tpl/kitex/server/standard/build_sh_tpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ update_behavior:
body: |-
#!/usr/bin/env bash
RUN_NAME="{{.RealServiceName}}"
mkdir -p output/bin output/conf
cp script/* output/
cp -r conf/* output/conf
Expand Down
1 change: 1 addition & 0 deletions tpl/kitex/server/standard/conf_dev_tpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ body: |-
mysql:
dsn: "gorm:gorm@tcp(127.0.0.1:3306)/gorm?charset=utf8&parseTime=True&loc=Local"
redis:
address: "127.0.0.1:6379"
username: ""
Expand Down
1 change: 1 addition & 0 deletions tpl/kitex/server/standard/conf_online_tpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ body: |-
mysql:
dsn: "gorm:gorm@tcp(127.0.0.1:3306)/gorm?charset=utf8&parseTime=True&loc=Local"
redis:
address: "127.0.0.1:6379"
username: ""
Expand Down
1 change: 1 addition & 0 deletions tpl/kitex/server/standard/conf_test_tpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ body: |-
mysql:
dsn: "gorm:gorm@tcp(127.0.0.1:3306)/gorm?charset=utf8&parseTime=True&loc=Local"
redis:
address: "127.0.0.1:6379"
username: ""
Expand Down
2 changes: 2 additions & 0 deletions tpl/kitex/server/standard/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ body: |-
{{- if .Void}}
{{- if .Oneway}}
{{- end}}
// New{{.Name}}Service new {{.Name}}Service
func New{{.Name}}Service(ctx context.Context) *{{.Name}}Service {
return &{{.Name}}Service{ctx: ctx}
Expand All @@ -52,6 +53,7 @@ body: |-
return nil
}
{{else -}}
// New{{.Name}}Service new {{.Name}}Service
func New{{.Name}}Service(ctx context.Context) *{{.Name}}Service {
return &{{.Name}}Service{ctx: ctx}
Expand Down
1 change: 0 additions & 1 deletion tpl/kitex/server/standard/service_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ body: |-
{{- end}}
)
{{range .Methods}}
func Test{{.Name}}_Run(t *testing.T) {
Expand Down

0 comments on commit e149312

Please sign in to comment.