|
6 | 6 | {{- $stdlibImports := dict -}}
|
7 | 7 | {{- set $stdlibImports "context" "" -}}
|
8 | 8 | {{- set $stdlibImports "errors" "" -}}
|
9 |
| -{{- set $stdlibImports "encoding/json" "" -}} |
10 | 9 | {{- set $stdlibImports "fmt" "" -}}
|
11 | 10 | {{- set $stdlibImports "io/ioutil" "" -}}
|
12 | 11 | {{- set $stdlibImports "net/http" "" -}}
|
13 | 12 |
|
| 13 | +{{- if eq $opts.json "stdlib" -}} |
| 14 | + {{- set $stdlibImports "encoding/json" "" -}} |
| 15 | +{{- end -}} |
| 16 | + |
14 | 17 | {{- if $opts.client}}
|
15 | 18 | {{- set $stdlibImports "bytes" "" -}}
|
16 | 19 | {{- set $stdlibImports "io" "" -}}
|
|
33 | 36 | {{- end -}}
|
34 | 37 | {{- end -}}
|
35 | 38 |
|
| 39 | +import ( |
| 40 | + |
36 | 41 | {{- /* Print stdlib imports. */ -}}
|
37 | 42 | {{- range $import, $rename := $stdlibImports }}
|
38 | 43 | {{if ne $rename ""}}{{$rename}} {{end}}"{{$import}}"
|
39 | 44 | {{- end -}}
|
40 | 45 |
|
| 46 | +{{- /* Print custom type imports. */ -}} |
| 47 | +{{ $imports := dict }} |
| 48 | + |
| 49 | +{{- if eq $opts.json "stdlib" -}} |
| 50 | + {{- /* Already imported in the stdlib section. */ -}} |
| 51 | +{{- else if eq $opts.json "jsoniter" -}} |
| 52 | + {{- set $imports "github.com/json-iterator/go" "jsoniter" -}} |
| 53 | +{{- else -}} |
| 54 | + {{- stderrPrintf "unsupported -json=%s" $opts.json -}} |
| 55 | + {{- exit 1 -}} |
| 56 | +{{- end -}} |
| 57 | + |
41 | 58 | {{ if ne $opts.importTypesFrom "" }}
|
42 | 59 |
|
43 | 60 | "{{ $opts.importTypesFrom }}"
|
44 | 61 | {{- else }}
|
45 |
| - {{- /* Print custom type imports. */ -}} |
46 |
| - {{ $imports := dict }} |
47 | 62 | {{ range $_, $type := $types -}}
|
48 | 63 | {{- range $_, $field := $type.Fields -}}
|
49 | 64 | {{- range $meta := $field.Meta -}}
|
|
56 | 71 | {{- range $import, $rename := $imports }}
|
57 | 72 | {{if ne $rename ""}}{{$rename}} {{end}}"{{$import}}"
|
58 | 73 | {{- end -}}
|
59 |
| -{{- end }} |
| 74 | +{{ end }} |
| 75 | +) |
| 76 | + |
| 77 | +{{- if eq $opts.json "jsoniter" }} |
| 78 | + |
| 79 | +var json = jsoniter.ConfigCompatibleWithStandardLibrary |
| 80 | +{{ end -}} |
60 | 81 |
|
61 | 82 | {{- end -}}
|
0 commit comments