-
Notifications
You must be signed in to change notification settings - Fork 22
/
generate.tmpl
39 lines (38 loc) · 1.42 KB
/
generate.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
32
33
34
35
36
37
38
39
{{- define "JoinFields"}}
{{- range $key, $Type := . -}}
{{- if ne $key 0}}, {{end -}}
{{- $Type.Name -}}
{{- end -}}
{{end -}}
{{- define "JoinParameters"}}
{{- range $key, $Type := . -}}
{{- if ne $key 0}}, {{end}}
{{- $Type.Field.VariableName}} {{$Type.Name}}
{{- end -}}
{{end -}}
{{ .Keep| bytesToString -}}
{{range $functionKey, $function := .Functions}}
// {{$function.Name}} copies a {{template "JoinFields" $function.From}} to a {{template "JoinFields" $function.To}}.
func {{$function.Name}}({{template "JoinParameters" $function.To}}, {{template "JoinParameters" $function.From}}) {
{{- range $typeKey, $toType := $function.To}}
// {{$toType.Name}} fields
{{- range $fieldKey, $toField := $toType.Field.AllFields nil nil -}}
{{- if $toField.From }}
{{$toField.FullVariableName ""}} = {{""}}
{{- with $fromField := $toField.From -}}
{{- if ne $fromField.Options.Convert "" -}}
{{$fromField.Options.Convert}}({{$fromField.FullVariableName ""}})
{{- else -}}
{{- if eq $toField.FullDefinition $fromField.FullDefinition -}}
{{$fromField.FullVariableName ""}}
{{- else if eq (slice $toField.FullDefinition 1) $fromField.FullDefinition -}}
&{{$fromField.FullVariableName ""}}
{{- else if eq $toField.FullDefinition (slice $fromField.FullDefinition 1) -}}
*{{$fromField.FullVariableName ""}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end}}
{{end}}}
{{end}}