diff --git a/_examples/smoke/example.gen.c b/_examples/smoke/example.gen.c index 0cbf4ca..0e736ec 100644 --- a/_examples/smoke/example.gen.c +++ b/_examples/smoke/example.gen.c @@ -1,20 +1,3 @@ - - - - - - - - - - - - - - - - - // smoke v1.0.0 6dc82371b24d044c3b3e2bd4cf5d92af46788fff // -- // Code generated by webrpc-gen@v0.37.1 with .. generator. DO NOT EDIT. diff --git a/impl.go.tmpl b/impl.go.tmpl index 2bad123..023d02a 100644 --- a/impl.go.tmpl +++ b/impl.go.tmpl @@ -2,8 +2,8 @@ {{- $prefix := .Prefix -}} {{- $encodeReachable := dict -}} {{- $decodeReachable := dict -}} -{{ template "collectStructCodecReachability" dict "Types" .Types "Services" .Services "EncodeReachable" $encodeReachable "DecodeReachable" $decodeReachable }} -{{ template "implPreamble" . }} +{{- template "collectStructCodecReachability" dict "Types" .Types "Services" .Services "EncodeReachable" $encodeReachable "DecodeReachable" $decodeReachable -}} +{{- template "implPreamble" . }} {{ template "implTransport" . }} {{- range $_, $type := .Types }} diff --git a/implCodecReachability.go.tmpl b/implCodecReachability.go.tmpl index e6ecf71..884c7d7 100644 --- a/implCodecReachability.go.tmpl +++ b/implCodecReachability.go.tmpl @@ -3,13 +3,13 @@ {{- $types := .Types -}} {{- $reachable := .Reachable -}} {{- if isMapType $type }} -{{ template "markStructCodecReachability" dict "Type" (mapValueType $type) "Types" $types "Reachable" $reachable }} +{{- template "markStructCodecReachability" dict "Type" (mapValueType $type) "Types" $types "Reachable" $reachable -}} {{- else if isListType $type }} -{{ template "markStructCodecReachability" dict "Type" (listElemType $type) "Types" $types "Reachable" $reachable }} +{{- 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 }} +{{- template "markStructCodecReachability" dict "Type" $type.Alias.Type.Type "Types" $types "Reachable" $reachable -}} {{- else if isStructType $type }} {{- $typeName := toString $type -}} {{- if not (exists $reachable $typeName) }} @@ -17,7 +17,7 @@ {{- 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 }} +{{- template "markStructCodecReachability" dict "Type" $field.Type "Types" $types "Reachable" $reachable -}} {{- end }} {{- end }} {{- end }} @@ -32,10 +32,10 @@ {{- range $_, $service := .Services }} {{- range $_, $method := $service.Methods }} {{- range $_, $input := $method.Inputs }} -{{ template "markStructCodecReachability" dict "Type" $input.Type "Types" $types "Reachable" $encodeReachable }} +{{- 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 }} +{{- template "markStructCodecReachability" dict "Type" $output.Type "Types" $types "Reachable" $decodeReachable -}} {{- end }} {{- end }} {{- end }} diff --git a/main.go.tmpl b/main.go.tmpl index d5de45b..97ceee4 100644 --- a/main.go.tmpl +++ b/main.go.tmpl @@ -1,5 +1,4 @@ {{- define "main" -}} - {{- $opts := dict -}} {{- $defaultPrefix := (snakeCase .SchemaName) -}} {{- $emitClient := (ternary (eq (default .Opts.client "true") "false") false true) -}} @@ -38,7 +37,7 @@ {{- $prefix := $opts.prefix -}} {{- if eq $opts.emit "impl" -}} -{{ template "impl" dict "Prefix" $prefix "Header" $opts.header "SchemaName" .SchemaName "SchemaVersion" .SchemaVersion "SchemaHash" .SchemaHash "BasePath" (default (and (hasField . "BasePath") .BasePath) "/rpc/") "WebrpcGenVersion" .WebrpcGenVersion "WebrpcTarget" .WebrpcTarget "WebrpcGenCommand" .WebrpcGenCommand "Types" .Types "Services" .Services "Errors" .Errors "WebrpcErrors" .WebrpcErrors "Opts" $opts "Client" $emitClient }} +{{- template "impl" dict "Prefix" $prefix "Header" $opts.header "SchemaName" .SchemaName "SchemaVersion" .SchemaVersion "SchemaHash" .SchemaHash "BasePath" (default (and (hasField . "BasePath") .BasePath) "/rpc/") "WebrpcGenVersion" .WebrpcGenVersion "WebrpcTarget" .WebrpcTarget "WebrpcGenCommand" .WebrpcGenCommand "Types" .Types "Services" .Services "Errors" .Errors "WebrpcErrors" .WebrpcErrors "Opts" $opts "Client" $emitClient -}} {{- else -}} {{- $guard := printf "%s_%s_%s_H" (toUpper (snakeCase .SchemaName)) (toUpper (snakeCase $prefix)) (toUpper $opts.emit) -}} #ifndef {{$guard}}