Documentation ¶
Index ¶
- func AddKnownType(ctx context.Context, name string) error
- func Driver(ctx context.Context) string
- func Emit(ctx context.Context, tpl *Template) error
- func Errors(ctx context.Context) ([]error, error)
- func GenType(ctx context.Context) string
- func NthParam(ctx context.Context) func(int) string
- func Out(ctx context.Context) string
- func Process(ctx context.Context, doAppend bool, single string, order ...string) error
- func Register(typ string, set *TemplateSet)
- func Schema(ctx context.Context) string
- func Src(ctx context.Context) fs.FS
- func Suffix(ctx context.Context) string
- func TemplateType(ctx context.Context) string
- func Types() []string
- func Write(ctx context.Context) error
- func WriteFiles(ctx context.Context) error
- func WriteRaw(ctx context.Context) error
- type ContextKey
- type EmittedTemplate
- type Enum
- type EnumValue
- type ErrPostFailed
- type Field
- type Flag
- type FlagSet
- type ForeignKey
- type Index
- type Proc
- type Query
- type QueryParam
- type Template
- type TemplateSet
- func (set *TemplateSet) Emit(ctx context.Context, tpl *Template) error
- func (set *TemplateSet) Exec(ctx context.Context, tpl *Template) ([]byte, error)
- func (set *TemplateSet) Load(ctx context.Context, tpl *Template) (*template.Template, error)
- func (set *TemplateSet) LoadFile(ctx context.Context, file string, doAppend bool) ([]byte, error)
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddKnownType ¶
AddKnownType adds a known type name to a template set.
func TemplateType ¶
TemplateType returns type option from the context.
func Write ¶
Write performs post processing of emitted templates to a template set, writing to disk the processed content.
func WriteFiles ¶
WriteFiles writes the generated files to disk.
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey is a context key.
const ( GenTypeKey ContextKey = "gen-type" TemplateTypeKey ContextKey = "template-type" SuffixKey ContextKey = "suffix" DriverKey ContextKey = "driver" SchemaKey ContextKey = "schema" SrcKey ContextKey = "src" NthParamKey ContextKey = "nth-param" OutKey ContextKey = "out" )
Context keys.
type EmittedTemplate ¶
EmittedTemplate wraps a template with its content and file name.
type ErrPostFailed ¶
ErrPostFailed is the post failed error.
func (*ErrPostFailed) Error ¶
func (err *ErrPostFailed) Error() string
Error satisfies the error interface.
func (*ErrPostFailed) Unwrap ¶
func (err *ErrPostFailed) Unwrap() error
Unwrap satisfies the unwrap interface.
type Field ¶
type Field struct { Name string Type string Zero string Prec int Col *models.Column Comment string }
Field is a field template.
type Flag ¶
type Flag struct { ContextKey ContextKey Desc string PlaceHolder string Default string Short rune Value interface{} Enums []string }
Flag is a option flag.
type ForeignKey ¶
type ForeignKey struct { Name string Type *Type Field *Field RefType *Type RefField *Field ForeignKey *models.ForeignKey Comment string }
ForeignKey is a foreign key template.
type Proc ¶
type Proc struct { Name string ProcParams string Params []*Field Return *Field Proc *models.Proc Comment string }
Proc is a stored procedure template.
type Query ¶
type Query struct { Name string Query []string Comments []string Params []*QueryParam One bool Flat bool Interpolate bool Type *Type Comment string }
Query is a custom query template.
type QueryParam ¶
QueryParam is a custom query parameter template.
type Template ¶
type Template struct { Set string Template string Type string Name string Data interface{} Extra map[string]interface{} }
Template wraps other templates.
type TemplateSet ¶
type TemplateSet struct { // Files are the embedded templates. Files embed.FS // FileExt is the file extension added to out files. FileExt string // AddType will be called when a new type is encountered. AddType func(string) // Flags are additional template flags. Flags []Flag // HeaderTemplate is the name of the header template. HeaderTemplate func(context.Context) *Template // PackageTemplates returns package templates. PackageTemplates func(context.Context) []*Template // Funcs provides template funcs for use by templates. Funcs func(context.Context) (template.FuncMap, error) // FileName determines the out file name templates. FileName func(context.Context, *Template) string // Post performs post processing of generated content. Post func(context.Context, []byte) ([]byte, error) // contains filtered or unexported fields }
TemplateSet is a template set.
func (*TemplateSet) Emit ¶
func (set *TemplateSet) Emit(ctx context.Context, tpl *Template) error
Emit emits a template to the template set.
Directories ¶
Path | Synopsis |
---|---|
Package gotpl provides a Go template for xo.
|
Package gotpl provides a Go template for xo. |