output

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrInvalidDictParams = Error("invalid dict params in call to WithParams, must be key and value pairs")
	ErrInvalidDictKey    = Error("invalid dict params in call to WithParams, must be key and value pairs")
)
View Source
const (
	DBAll    = "DbAll"
	DBSchema = "DbSchema"
	DBTable  = "DbTable"
	DBEnums  = "DbEnums"
	DBEnum   = "DbEnum"
)
View Source
const (
	EmbedAll       = "EmbedAll"
	EmbedFileGroup = "EmbedFileGroup"
	EmbedFile      = "EmbedFile"
)
View Source
const (
	ErrMissingRequirement = Error("requires")
	ErrNotNeeded          = Error("not needed")
	ErrPermExists         = Error("file exists")
)
View Source
const (
	OpenAPIFile = "OpenAPIFile"
	OpenAPITag  = "OpenAPITag"
)
View Source
const (
	ProtoAll       = "ProtoAll"
	ProtoFileGroup = "ProtoFileGroup"
	ProtoFile      = "ProtoFile"
)
View Source
const (
	SQLAll   = "SQLAll"
	SQLFiles = "SQLFiles"
	SQLFile  = "SQLFile"
	SQLQuery = "SQLQuery"
)
View Source
const PermPrefix = "!"
View Source
const ValidTypeElems = 2

Variables

This section is empty.

Functions

func DB

func DB(p cfg.Process, fn cfg.FileHandler, logger zerolog.Logger, schemas db.DB, simulate bool) error

func Embed

func Embed(p cfg.Process, fn cfg.FileHandler, l zerolog.Logger, groups []input.FileGroup, simulate bool) error

func HasDBOutput

func HasDBOutput(o cfg.Output) bool

func HasEmbedOutput

func HasEmbedOutput(o cfg.Output) bool

func HasOpenAPIOutput

func HasOpenAPIOutput(o cfg.Output) bool

func HasProtoOutput

func HasProtoOutput(o cfg.Output) bool

func HasSQLOutput

func HasSQLOutput(o cfg.Output) bool

func OpenAPI

func OpenAPI(p cfg.Process, fn cfg.FileHandler, l zerolog.Logger, groups openapi.FileGroups, simulate bool) error

func Proto

func Proto(p cfg.Process, fn cfg.FileHandler, l zerolog.Logger, groups proto.PBFileGroups, simulate bool) error

func SQL

func SQL(p cfg.Process, fn cfg.FileHandler, l zerolog.Logger, fileGroups sql.FileGroups, simulate bool) error

Types

type Context

type Context struct {
	// RuntimeParams are used for parameterized sub-templates
	RuntimeParams
	// Process provides the details of the currently executing Process
	cfg.Process
	// Logger provides logging features to the context helpers and templates
	Logger zerolog.Logger
	// AbortError allows cancelling saving of a file.  See NotNeededIf.
	AbortError error
}

func (*Context) Aborted

func (c *Context) Aborted() error

Aborted is used to control file generation based on template execution. See NotNeededIf.

func (*Context) ErrorIf

func (c *Context) ErrorIf(t bool, reason string) (string, error)

ErrorIf if given bool is true the execution is fatally aborted, and stops processing.

func (*Context) Funcs

func (c *Context) Funcs() plates.FuncMap

Funcs defaults the default case funcs based on the Process.Case.

func (*Context) NotNeededIf

func (c *Context) NotNeededIf(t bool, reason string) (string, error)

NotNeededIf given bool is true the execution is aborted, and can be used to prevent generation of a file.

func (*Context) PackageName

func (c *Context) PackageName() string

PackageName is a helper to extract the package name from a fully qualified package. It uses the Process.Params.Package as the source. Params.Package "github.com/domain/repo/package/subpackage" => "subpackage".

func (*Context) ToCase

func (c *Context) ToCase(name string) string

ToCase uses the current default case to map the current string.

func (*Context) WithParams

func (c *Context) WithParams(values ...interface{}) (*Context, error)

WithParams Clones the current context and adds runtime params for each pair of key, value provided. Used for executing sub templates that still need access to the context.

type EmbedContext

type EmbedContext struct {
	Context
	FileGroups []input.FileGroup
}

type EmbedFileContext

type EmbedFileContext struct {
	EmbedFileGroupContext
	input.File
}

type EmbedFileGroupContext

type EmbedFileGroupContext struct {
	EmbedContext
	FileGroup input.FileGroup
}

type EnumContext

type EnumContext struct {
	db.Enum
	SchemasContext
}

type EnumsContext

type EnumsContext struct {
	db.Enums
	SchemasContext
}

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type FuncMapper

type FuncMapper interface {
	Funcs() plates.FuncMap
}

type Imports

type Imports stringlist.Strings

Imports tracks dynamic usage of objects. Because templates are executed in order, using this to populate a list at the top of a generated file requires precalculating all of the imports. See SQLContext.Init as an example. Another option would be to create a buffer of generated code at the beginning, then generate the final output.

func (*Imports) Add

func (ii *Imports) Add(s string)

Add filters duplicates and appends to the import list. Add works on uninitialized Imports objects.

func (*Imports) CheckPackage

func (ii *Imports) CheckPackage(t, pkg string) string

CheckPackage is used for type mapping. Currently it is designed for go fully qualified package names. Examples: "github.com/domain/repo/package/subpackage.Type", "" => "subpackage.Type" "time.Time", "" => "time.Time" "int", "" => "int" "github.com/domain/repo/package/subpackage.Type", "github.com/domain/repo/package/subpackage" => "Type" If the type is defined in a separate package the package is added to the import list.

type Initializer

type Initializer interface {
	Init() error
}

type OpResponse

type OpResponse struct {
	Key       string
	MimeType  string
	MediaType *openapi3.MediaType
	GoType    string
}

func (OpResponse) IsLongPollingOperation

func (op OpResponse) IsLongPollingOperation() bool

type OpenAPIFileContext

type OpenAPIFileContext struct {
	Context
	Imports
	openapi.File
}

func (*OpenAPIFileContext) CheckAllTypes

func (o *OpenAPIFileContext) CheckAllTypes()

func (*OpenAPIFileContext) GetOpHappyResponse

func (o *OpenAPIFileContext) GetOpHappyResponse(pkg string, op *openapi3.Operation) OpResponse

func (*OpenAPIFileContext) GetOpHappyResponseKey

func (o *OpenAPIFileContext) GetOpHappyResponseKey(op *openapi3.Operation) string

func (*OpenAPIFileContext) GetOpHappyResponseMimeType

func (o *OpenAPIFileContext) GetOpHappyResponseMimeType(op *openapi3.Operation) string

func (*OpenAPIFileContext) GetOpHappyResponseType

func (o *OpenAPIFileContext) GetOpHappyResponseType(pkg string, op *openapi3.Operation) string

func (*OpenAPIFileContext) GetType

func (o *OpenAPIFileContext) GetType(pkg, name string, s *openapi3.SchemaRef) string

func (*OpenAPIFileContext) GetTypeName

func (o *OpenAPIFileContext) GetTypeName(pkg string, s *openapi3.SchemaRef) string

func (*OpenAPIFileContext) HasAnyAuth

func (o *OpenAPIFileContext) HasAnyAuth(op *openapi3.Operation) bool

func (*OpenAPIFileContext) HasAuthorization

func (o *OpenAPIFileContext) HasAuthorization() bool

func (*OpenAPIFileContext) HasBasicAuth

func (o *OpenAPIFileContext) HasBasicAuth() bool

func (*OpenAPIFileContext) HasBearerAuth

func (o *OpenAPIFileContext) HasBearerAuth() bool

func (*OpenAPIFileContext) HasComplexAuth

func (o *OpenAPIFileContext) HasComplexAuth() bool

func (*OpenAPIFileContext) HasValidation

func (o *OpenAPIFileContext) HasValidation(s *openapi3.SchemaRef) bool

func (*OpenAPIFileContext) Init

func (o *OpenAPIFileContext) Init() error

func (*OpenAPIFileContext) IsDefaultEnum

func (o *OpenAPIFileContext) IsDefaultEnum(name string, s *openapi3.SchemaRef) bool

IsDefaultEnum helper that checks if an enumerated type is overridden (specified externally).

func (*OpenAPIFileContext) IsSimpleAuth

func (o *OpenAPIFileContext) IsSimpleAuth(op *openapi3.Operation) bool

func (*OpenAPIFileContext) OpSecurity

func (*OpenAPIFileContext) RefToName

func (o *OpenAPIFileContext) RefToName(ref string) string

func (*OpenAPIFileContext) RequiresAuthUser

func (o *OpenAPIFileContext) RequiresAuthUser(op *openapi3.Operation) bool

func (*OpenAPIFileContext) WithParams

func (o *OpenAPIFileContext) WithParams(values ...interface{}) (*OpenAPIFileContext, error)

type ProcessRunner

type ProcessRunner struct {
	*plates.Factory
	// contains filtered or unexported fields
}

func NewProcessRunner

func NewProcessRunner(dir string, fn cfg.FileHandler, l zerolog.Logger, simulate bool) ProcessRunner

type Properties

type Properties []*Property

type Property

type Property struct {
	Name   string
	Type   string
	Format string
}

type ProtoContext

type ProtoContext struct {
	Context
	Imports
	FileGroups proto.PBFileGroups
}

func (ProtoContext) GetType

func (q ProtoContext) GetType(f proto.Field, pkg string) string

func (ProtoContext) HasMessage

func (q ProtoContext) HasMessage(msg *proto.Message) bool

func (ProtoContext) IsEnum

func (q ProtoContext) IsEnum(name string) bool

func (ProtoContext) IsMessage

func (q ProtoContext) IsMessage(name string) bool

type ProtoFileContext

type ProtoFileContext struct {
	ProtoFileGroupContext
	proto.PBFile
}

type ProtoFileGroupContext

type ProtoFileGroupContext struct {
	ProtoContext
	FileGroup proto.PBFileGroup
}

type Resource

type Resource struct {
	Name       string
	Properties Properties
	Table      *db.Table
	PK         *Property
}

type ResourceMap

type ResourceMap map[string]Resource

type RuntimeParams

type RuntimeParams map[string]interface{}

type SQLContext

type SQLContext struct {
	Context
	sql.FileGroups
	Imports
}

func (SQLContext) GetType

func (q SQLContext) GetType(c *sql.Param, pkg string) string

func (*SQLContext) Init

func (q *SQLContext) Init() error

func (SQLContext) Parameterize

func (q SQLContext) Parameterize(cc sql.Params, format, pkg string) string

type SQLFileContext

type SQLFileContext struct {
	SQLContext
	sql.File
}

func (*SQLFileContext) Init

func (q *SQLFileContext) Init() error

type SQLFileGroupContext

type SQLFileGroupContext struct {
	SQLContext
	Files []sql.File
}

func (*SQLFileGroupContext) Init

func (q *SQLFileGroupContext) Init() error

type SQLQueryContext

type SQLQueryContext struct {
	SQLContext
	sql.Query
}

func (*SQLQueryContext) Init

func (q *SQLQueryContext) Init() error

type SchemaContext

type SchemaContext struct {
	db.Schema
	SchemasContext
}

type SchemasContext

type SchemasContext struct {
	Context
	Imports
	db.DB
}

func (SchemasContext) GetType

func (s SchemasContext) GetType(c *db.Column, pkg string) string

func (*SchemasContext) Parameterize

func (s *SchemasContext) Parameterize(cc db.Columns, format, pkg string) string

func (SchemasContext) PropertiesFromDB

func (s SchemasContext) PropertiesFromDB(cc db.Columns) Properties

func (SchemasContext) PropertyFromDB

func (s SchemasContext) PropertyFromDB(c *db.Column) *Property

func (SchemasContext) Resources

func (s SchemasContext) Resources() ResourceMap

type TableContext

type TableContext struct {
	db.Table
	SchemasContext
}

Jump to

Keyboard shortcuts

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