Skip to content

Commit

Permalink
Fix imports & formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVitek committed Apr 3, 2024
1 parent 4ae54d6 commit 09bae60
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
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

0 comments on commit 09bae60

Please sign in to comment.