forked from webrpc/gen-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct.go.tmpl
31 lines (30 loc) · 1.09 KB
/
struct.go.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{{- define "struct" -}}
{{- $struct := .Struct -}}
{{- $typeMap := .TypeMap -}}
type {{$struct.Name}} struct {
{{- range $_, $field := $struct.Fields -}}
{{- $fieldName := $field.Name | firstLetterToUpper -}}
{{- $customType := "" -}}
{{- $jsonTags := printf "json:%q" $field.Name }}
{{- $dbTags := "" }}
{{- range $meta := $field.Meta -}}
{{- if exists $meta "go.field.name" -}}
{{- $fieldName = get $meta "go.field.name" -}}
{{- end -}}
{{- if exists $meta "go.field.type" -}}
{{- $customType = get $meta "go.field.type" -}}
{{- end -}}
{{- if exists $meta "json" -}}
{{- $jsonTags = printf "json:%q" (get $meta "json") -}}
{{- end -}}
{{- if exists $meta "go.tag.json" -}}
{{- $jsonTags = printf "json:%q" (get $meta "go.tag.json") -}}
{{- end -}}
{{- if exists $meta "go.tag.db" -}}
{{- $dbTags = printf " db:%q" (get $meta "go.tag.db") -}}
{{- end -}}
{{- end }}
{{$fieldName}} {{if ne $customType ""}}{{$customType}}{{else}}{{template "type" dict "Type" $field.Type "Optional" $field.Optional "TypeMap" $typeMap}}{{end}} `{{$jsonTags}}{{$dbTags}}`
{{- end}}
}
{{- end }}