Skip to content

Commit 393237f

Browse files
authored
Add an example custom type, which renders a pointer incorrectly (#3)
* Add an example custom type, which renders a pointer incorrectly webrpc/webrpc#127 * Fix an extra pointer in front of custom type Fixes webrpc/webrpc#127
1 parent 39b527d commit 393237f

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

Diff for: _examples/golang-basics/example.gen.go

+10-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: _examples/golang-basics/example.ridl

+14-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ enum Kind: uint32
88
- USER
99
- ADMIN
1010

11-
12-
message Empty
13-
14-
1511
message User
1612
- id: uint64
1713
+ json = id
@@ -26,12 +22,26 @@ message User
2622
- role: string
2723
+ go.tag.db = -
2824

25+
- nicknames: []Nickname
26+
+ go.tag.db = "-"
27+
+ go.field.type = []Nickname
28+
2929
- createdAt: timestamp
3030
+ go.tag.db = created_at
3131

3232
- updatedAt?: timestamp
3333
+ go.tag.db = updated_at
3434

35+
message Nickname
36+
- id: uint64
37+
+ go.tag.db = id
38+
- nickname: string
39+
+ go.tag.db = nickname
40+
- createdAt: timestamp
41+
+ go.tag.db = created_at
42+
- updatedAt?: timestamp
43+
+ go.tag.db = updated_at
44+
3545
message SearchFilter
3646
- q: string
3747

Diff for: struct.go.tmpl

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
type {{$struct.Name}} struct {
66
{{- range $_, $field := $struct.Fields -}}
77
{{- $fieldName := $field.Name | firstLetterToUpper -}}
8-
{{- $fieldType := $field.Type -}}
8+
{{- $customType := "" -}}
99
{{- $jsonTags := printf "json:%q" ($field.Name | firstLetterToLower) }}
1010
{{- $dbTags := "" }}
1111
{{- range $meta := $field.Meta -}}
1212
{{- if exists $meta "go.field.name" -}}
1313
{{- $fieldName = get $meta "go.field.name" -}}
1414
{{- end -}}
1515
{{- if exists $meta "go.field.type" -}}
16-
{{- $fieldType = get $meta "go.field.type" -}}
16+
{{- $customType = get $meta "go.field.type" -}}
1717
{{- end -}}
1818
{{- if exists $meta "json" -}}
1919
{{- $jsonTags = printf "json:%q" (get $meta "json") -}}
@@ -25,7 +25,7 @@ type {{$struct.Name}} struct {
2525
{{- $dbTags = printf " db:%q" (get $meta "go.tag.db") -}}
2626
{{- end -}}
2727
{{- end }}
28-
{{$fieldName}} {{if and $field.Optional (not (isStructType $field.Type))}}*{{end}}{{template "type" dict "Type" $fieldType "TypeMap" $typeMap}} `{{$jsonTags}}{{$dbTags}}`
28+
{{$fieldName}} {{if ne $customType ""}}{{$customType}}{{else}}{{if and $field.Optional (not (isStructType $field.Type))}}*{{end}}{{template "type" dict "Type" $field.Type "TypeMap" $typeMap}}{{end}} `{{$jsonTags}}{{$dbTags}}`
2929
{{- end}}
3030
}
3131
{{- end }}

0 commit comments

Comments
 (0)