templates

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2023 License: MIT Imports: 0 Imported by: 0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL