Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix imports & formatting #59

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _examples/golang-basics/example.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions _examples/golang-imports/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions imports.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,28 @@ import (
{{- set $imports $opts.importTypesFrom "" -}}
{{- else -}}
{{- range $_, $type := $types -}}
{{- range $_, $field := $type.Fields -}}
{{- range $meta := $field.Meta -}}
{{- /* TODO: We might need to loop through method args too. */ -}}
{{- range $meta := $type.Meta -}}
{{- if exists $meta "go.type.import" -}}
{{- set $imports (get $meta "go.type.import") "" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if $opts.types }}
{{- range $_, $field := $type.Fields -}}
{{- range $meta := $field.Meta -}}
{{- if exists $meta "go.type.import" -}}
{{- set $imports (get $meta "go.type.import") "" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end }}
{{- end -}}
{{- end }}
{{- if $opts.types }}
{{ range $import, $rename := $imports }}
{{- if not (exists $stdlibImports $import)}}
{{if ne $rename ""}}{{$rename}} {{end}}"{{$import}}"
{{end}}
{{- end }}
{{- end }}
{{- end -}}
)

{{- if eq $opts.json "jsoniter" }}
Expand Down
16 changes: 8 additions & 8 deletions types.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
{{- $services := .Services -}}
{{- $opts := .Opts -}}

{{- if $types }}
//
// Types
// Common types
//
{{ range $_, $type := $types -}}

{{- if eq $type.Kind "enum" }}
{{- if eq $type.Type.Expr "string" }}
{{template "enum_string" dict "Name" $type.Name "Type" $type.Type "TypePrefix" $typePrefix "Fields" $type.Fields "Opts" $opts}}
{{ else }}
{{- else }}
{{template "enum" dict "Name" $type.Name "Type" $type.Type "TypePrefix" $typePrefix "Fields" $type.Fields "Opts" $opts}}
{{ end -}}
{{- end -}}
{{ end -}}

{{- if and (eq $type.Kind "struct") $opts.types }}
Expand All @@ -28,8 +27,7 @@
{{template "struct" dict "Name" $type.Name "TypeMap" $typeMap "TypePrefix" $typePrefix "Fields" $type.Fields}}
{{ end -}}

{{ end }}
{{ end -}}
{{- end }}

var WebRPCServices = map[string][]string{
{{- range $_, $service := $services}}
Expand All @@ -46,6 +44,7 @@ var WebRPCServices = map[string][]string{
//

{{ range $_, $service := $services -}}
{{ if $opts.types -}}
type {{$service.Name}} interface {
{{- range $_, $method := $service.Methods}}
{{ if eq $method.StreamOutput true -}}
Expand All @@ -56,9 +55,10 @@ type {{$service.Name}} interface {

{{- end}}
}
{{- end }}

{{- range $_, $method := $service.Methods}}
{{ if eq $method.StreamOutput true -}}
{{- range $_, $method := $service.Methods -}}
{{ if eq $method.StreamOutput true }}
type {{$method.Name}}StreamWriter interface {
Write({{range $i, $output := $method.Outputs}}{{if gt $i 0}}, {{end}}{{$output.Name}} {{template "field" dict "Name" $output.Name "Type" $output.Type "Optional" $output.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $output.Meta}}{{end}}) error
}
Expand Down
Loading