Documentation
¶
Index ¶
Constants ¶
View Source
const AFOPTemplate = TemplateBase + `
type {{ .structName }}Option interface {
apply(*{{ .structName }})
}
{{ range .fields }}{{ if ne .Ignore true}}
type {{ .Name }}Option struct {
{{ .Name }} {{ .Type }}
}
func (o {{ .Name }}Option) apply(s *{{ $.structName }}) {
s.{{ .Name }} = o.{{ .Name }}
}
{{ end }}{{ end }}
func New{{ .structName }}(options ...{{ .structName }}Option) *{{ .structName }} {
s := &{{ .structName }}{}
for _, option := range options {
option.apply(s)
}
return s
}
`
View Source
const AFOPTemplateWithoutNew = TemplateBase + `
type {{ .structName }}Option interface {
apply(*{{ .structName }})
}
{{ range .fields }}{{ if ne .Ignore true}}
type {{ .Name }}Option struct {
{{ .Name }} {{ .Type }}
}
func (o {{ .Name }}Option) apply(s *{{ $.structName }}) {
s.{{ .Name }} = o.{{ .Name }}
}
func With{{ .Name }}({{ .Name }} {{ .Type }}) {{ $.structName }}Option {
return func(args *{{ $.structName }}) {
args.{{ .Name }} = {{ .Name }}
}
}
{{ end }}{{ end }}`
View Source
const FOPTemplate = TemplateBase + `
type {{ .structName }}Option func(*{{ .structName }})
func New{{ .structName }}(options ...{{ .structName }}Option) *{{ .structName }} {
s := &{{ .structName }}{}
for _, option := range options {
option(s)
}
return s
}
{{ range .fields }}{{ if ne .Ignore true}}
func With{{ .Name }}({{ .Name }} {{ .Type }}) {{ $.structName }}Option {
return func(args *{{ $.structName }}) {
args.{{ .Name }} = {{ .Name }}
}
}
{{ end }}{{ end }}`
View Source
const FOPTemplateWithoutNew = TemplateBase + `
type {{ .structName }}Option func(*{{ .structName }})
{{ range .fields }}{{ if ne .Ignore true}}
func With{{ .Name }}({{ .Name }} {{ .Type }}) {{ $.structName }}Option {
return func(args *{{ $.structName }}) {
args.{{ .Name }} = {{ .Name }}
}
}
{{ end }}{{ end }}`
View Source
const TemplateBase = `// Code generated by foggo; DO NOT EDIT.
package {{ .pkgName }}
`
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.