fix templates

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-02-02 11:13:29 +03:00
parent 31e99273ca
commit e173bffd10
8 changed files with 44 additions and 42 deletions

2
.gitignore vendored
View File

@ -23,3 +23,5 @@ gin-bin
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
/protoc-gen-micro

File diff suppressed because one or more lines are too long

View File

@ -103,9 +103,6 @@ func (e *GenericTemplateBasedEncoder) templates() ([]string, error) {
name = string(dname)
}
for _, component := range components {
if debug {
log.Printf("check file template %s for %s", name, "_"+component+".pb.go.tmpl")
}
if component == "all" || strings.Contains(name, "_"+component+".pb.go.tmpl") {
skip = false
}

View File

@ -134,7 +134,9 @@ var ProtoHelpersFuncMap = template.FuncMap{
}
return a / b
},
"lenght": func(a []interface{}) int {
return len(a)
},
"snakeCase": xstrings.ToSnakeCase,
"getProtoFile": getProtoFile,
"getMessageType": getMessageType,

Binary file not shown.

View File

@ -20,7 +20,7 @@ func RouteName(ctx context.Context) (string, bool) {
return value, ok
}
func Register(r *chi.Mux, h interface{}, eps []*micro_api.Endpoint) error {
func {{.Service.Name | trimSuffix "Service"}}ServiceRegister(r *chi.Mux, h interface{}, eps []*micro_api.Endpoint) error {
v := reflect.ValueOf(h)
if v.NumMethod() < 1 {

View File

@ -11,7 +11,7 @@ import (
micro_api "github.com/unistack-org/micro/v3/api"
)
func Register(r *mux.Router, h interface{}, eps []*micro_api.Endpoint) error {
func {{.Service.Name | trimSuffix "Service"}}ServiceRegister(r *mux.Router, h interface{}, eps []*micro_api.Endpoint) error {
v := reflect.ValueOf(h)
if v.NumMethod() < 1 {

View File

@ -2,9 +2,26 @@
// source: {{.File.Name}}
package {{goPkgLastElement .File | splitArray ";" | last | replace "." "_"}}
{{- $File := .File }}
{{- $ServiceName := .Service.Name | trimSuffix "Service" }}
{{- $errmsg := list }}
{{range .Service.Method}}
{{- if not (contains (json (openapiOption .)) "null") }}
{{- if (openapiOption .).Responses }}
{{ range $k, $v := (openapiOption .).Responses }}
{{- $msgtype := (getMessageType $File $v.Schema.JsonSchema.Ref) }}
{{- $errmsg = append $errmsg $msgtype.Name }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
import (
"context"
{{- if ne (lenght $errmsg) 0 }}
"fmt"
{{- end }}
micro_client "github.com/unistack-org/micro/v3/client"
micro_server "github.com/unistack-org/micro/v3/server"
@ -16,9 +33,6 @@ var (
_ micro_client.Option
)
{{- $File := .File }}
{{- $ServiceName := .Service.Name | trimSuffix "Service" }}
type {{$ServiceName | lowerFirst}}Service struct {
c micro_client.Client
name string
@ -211,19 +225,6 @@ func (x *{{$ServiceName | lowerFirst}}{{.Name}}Stream) Recv() (*{{$reqMethod}},
{{end}}
{{end}}
{{- $errmsg := list }}
{{range .Service.Method}}
{{- if not (contains (json (openapiOption .)) "null") }}
{{- if (openapiOption .).Responses }}
{{ range $k, $v := (openapiOption .).Responses }}
{{- $msgtype := (getMessageType $File $v.Schema.JsonSchema.Ref) }}
{{- $errmsg = append $errmsg $msgtype.Name }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{range $k, $v := ($errmsg | uniq) }}
// Error method to satisfy error interface
func (e *{{- $v }}) Error() string {