Skip to content

Commit

Permalink
fix: init default values when using liner allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
joway committed Jun 5, 2024
1 parent af85f3d commit e5b9ca5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
10 changes: 5 additions & 5 deletions generator/golang/templates/slim/slim.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func New{{$TypeName}}() *{{$TypeName}} {
}
}
{{if Features.FrugalTag}}
func (p *{{$TypeName}}) InitDefault() {
*p = {{$TypeName}}{
{{template "StructLikeDefault" .}}
}
{{- range .Fields}}
{{- if .IsSetDefault}}
p.{{.GoName}} = {{.DefaultValue}}
{{- end}}
{{- end}}
}
{{end}}{{/* if Features.FrugalTag */}}
{{template "FieldGetOrSet" .}}
Expand Down
13 changes: 8 additions & 5 deletions generator/golang/templates/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ func New{{$TypeName}}() *{{$TypeName}} {
}
}
{{if Features.FrugalTag}}
func (p *{{$TypeName}}) InitDefault() {
*p = {{$TypeName}}{
{{template "StructLikeDefault" .}}
}
{{- range .Fields}}
{{- if .IsSetDefault}}
p.{{.GoName}} = {{.DefaultValue}}
{{- end}}
{{- end}}
}
{{end}}{{/* if Features.FrugalTag */}}
{{template "FieldGetOrSet" .}}
Expand Down Expand Up @@ -650,6 +650,7 @@ var FieldReadMap = `
{{- $ctx := (.ValCtx.WithTarget $val).WithFieldMask $curFieldMask}}
{{- if $isStructVal}}
{{$val}} := &values[i]
{{$val}}.InitDefault()
{{- else}}
{{- $ctx = $ctx.WithDecl}}
{{- end}}
Expand Down Expand Up @@ -698,6 +699,7 @@ var FieldReadSet = `
{{- $ctx := (.ValCtx.WithTarget $val).WithFieldMask $curFieldMask}}
{{- if $isStructVal}}
{{$val}} := &values[i]
{{$val}}.InitDefault()
{{- else}}
{{- $ctx = $ctx.WithDecl}}
{{- end}}
Expand Down Expand Up @@ -746,6 +748,7 @@ var FieldReadList = `
{{- $ctx := (.ValCtx.WithTarget $val).WithFieldMask $curFieldMask}}
{{- if $isStructVal}}
{{$val}} := &values[i]
{{$val}}.InitDefault()
{{- else}}
{{- $ctx = $ctx.WithDecl}}
{{- end}}
Expand Down

0 comments on commit e5b9ca5

Please sign in to comment.