-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplCodecReachability.go.tmpl
More file actions
42 lines (41 loc) · 1.86 KB
/
implCodecReachability.go.tmpl
File metadata and controls
42 lines (41 loc) · 1.86 KB
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
40
41
42
{{- define "markStructCodecReachability" -}}
{{- $type := .Type -}}
{{- $types := .Types -}}
{{- $reachable := .Reachable -}}
{{- if isMapType $type }}
{{- template "markStructCodecReachability" dict "Type" (mapValueType $type) "Types" $types "Reachable" $reachable -}}
{{- else if isListType $type }}
{{- template "markStructCodecReachability" dict "Type" (listElemType $type) "Types" $types "Reachable" $reachable -}}
{{- else if isCoreType $type }}
{{- else if isEnumType $type }}
{{- else if and (hasField $type "Alias") $type.Alias }}
{{- template "markStructCodecReachability" dict "Type" $type.Alias.Type.Type "Types" $types "Reachable" $reachable -}}
{{- else if isStructType $type }}
{{- $typeName := toString $type -}}
{{- if not (exists $reachable $typeName) }}
{{- $_ := set $reachable $typeName true -}}
{{- range $_, $candidate := $types }}
{{- if and (isStructType $candidate) (eq $candidate.Name $typeName) }}
{{- range $_, $field := $candidate.Fields }}
{{- template "markStructCodecReachability" dict "Type" $field.Type "Types" $types "Reachable" $reachable -}}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end -}}
{{- define "collectStructCodecReachability" -}}
{{- $types := .Types -}}
{{- $encodeReachable := .EncodeReachable -}}
{{- $decodeReachable := .DecodeReachable -}}
{{- range $_, $service := .Services }}
{{- range $_, $method := $service.Methods }}
{{- range $_, $input := $method.Inputs }}
{{- template "markStructCodecReachability" dict "Type" $input.Type "Types" $types "Reachable" $encodeReachable -}}
{{- end }}
{{- range $_, $output := $method.Outputs }}
{{- template "markStructCodecReachability" dict "Type" $output.Type "Types" $types "Reachable" $decodeReachable -}}
{{- end }}
{{- end }}
{{- end }}
{{- end -}}