output

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 23 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 (
	ErrMissingRequirement = Error("requires")
	ErrNotNeeded          = Error("not needed")
	ErrPermExists         = Error("file exists")
)
View Source
const (
	ApplicationJSON  = "application/json"
	ApplicationJSONL = "application/jsonl"
	TextPlain        = "text/plain"
	TextHTML         = "text/html"
	TextCSV          = "text/csv"
)
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 HasDBOutput

func HasDBOutput(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 ...any) (*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 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 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, currentPackage 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 MimeType added in v0.1.3

type MimeType string

func (MimeType) IsCSV added in v0.1.3

func (m MimeType) IsCSV() bool

func (MimeType) IsHTML added in v0.1.3

func (m MimeType) IsHTML() bool

func (MimeType) IsJson added in v0.1.3

func (m MimeType) IsJson() bool

func (MimeType) IsLongPollingOperation added in v0.1.3

func (m MimeType) IsLongPollingOperation() bool

func (MimeType) IsText added in v0.1.3

func (m MimeType) IsText() bool

func (MimeType) String added in v0.1.3

func (m MimeType) String() string

type OpBody added in v0.0.7

type OpBody struct {
	MimeType
	Schema *openapi3.SchemaRef
}

type OpResponse

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

type OpenAPIFileContext

type OpenAPIFileContext struct {
	Context
	Imports
	openapi.File
}

func (*OpenAPIFileContext) CheckAllTypes

func (o *OpenAPIFileContext) CheckAllTypes(pkg string, types ...string) string

CheckAllTypes is a helper to iterate all property references for import requirements. This is expected to inject imports for unnecessary packages depending on the template generated, the post-processing should remove unused imports.

func (*OpenAPIFileContext) ComponentParameters added in v0.1.0

func (o *OpenAPIFileContext) ComponentParameters() openapi3.ParametersMap

func (*OpenAPIFileContext) ComponentSchemas added in v0.1.0

func (o *OpenAPIFileContext) ComponentSchemas() openapi3.Schemas

func (*OpenAPIFileContext) DefaultValues added in v0.1.0

func (o *OpenAPIFileContext) DefaultValues(val string) []string

func (*OpenAPIFileContext) EnumName added in v0.1.0

func (o *OpenAPIFileContext) EnumName(name string) string

func (*OpenAPIFileContext) EnumNew added in v0.1.0

func (o *OpenAPIFileContext) EnumNew(name string) string

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) GetRequestBody added in v0.0.7

func (o *OpenAPIFileContext) GetRequestBody(op *openapi3.Operation) *OpBody

func (*OpenAPIFileContext) GetRequestBodyLocal added in v0.0.7

func (o *OpenAPIFileContext) GetRequestBodyLocal(op *openapi3.Operation) *openapi3.SchemaRef

func (*OpenAPIFileContext) GetType

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

func (*OpenAPIFileContext) GetTypeName

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

func (*OpenAPIFileContext) GoImports added in v0.0.7

func (o *OpenAPIFileContext) GoImports() []string

func (*OpenAPIFileContext) HasAnyAuth

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

func (*OpenAPIFileContext) HasAuthentication added in v0.0.7

func (o *OpenAPIFileContext) HasAuthentication() 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) HasExtension added in v0.1.0

func (o *OpenAPIFileContext) HasExtension(s *openapi3.SchemaRef, ext string) 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) IsRequiredProperty added in v0.1.14

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

IsRequiredProperty helper that checks if a property is required.

func (*OpenAPIFileContext) IsSimpleAuth

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

func (*OpenAPIFileContext) OpParams added in v0.1.0

func (*OpenAPIFileContext) OpSecurity

func (*OpenAPIFileContext) ParamIsEnum added in v0.1.0

func (o *OpenAPIFileContext) ParamIsEnum(param *openapi3.ParameterRef) bool

func (*OpenAPIFileContext) ParamIsEnumArray added in v0.1.0

func (o *OpenAPIFileContext) ParamIsEnumArray(param *openapi3.ParameterRef) bool

func (*OpenAPIFileContext) ParamIsOptionalType added in v0.1.0

func (o *OpenAPIFileContext) ParamIsOptionalType(param *openapi3.ParameterRef) bool

func (*OpenAPIFileContext) RefToName

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

func (*OpenAPIFileContext) RequiresAuthUser

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

func (*OpenAPIFileContext) SchemaEnums added in v0.1.0

func (o *OpenAPIFileContext) SchemaEnums(schema *openapi3.SchemaRef) openapi3.Schemas

func (*OpenAPIFileContext) SchemaIsComplex added in v0.1.0

func (o *OpenAPIFileContext) SchemaIsComplex(schema *openapi3.SchemaRef) bool

func (*OpenAPIFileContext) SchemaProperties added in v0.1.0

func (o *OpenAPIFileContext) SchemaProperties(schema *openapi3.SchemaRef, includeRefs bool) openapi3.Schemas

func (*OpenAPIFileContext) StripArray added in v0.1.0

func (o *OpenAPIFileContext) StripArray(name string) string

func (*OpenAPIFileContext) TypeOnly added in v0.0.7

func (o *OpenAPIFileContext) TypeOnly(name string) string

func (*OpenAPIFileContext) WithParams

func (o *OpenAPIFileContext) WithParams(values ...any) (*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]any

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(p *plates.Factory) 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
}

type TemplateInitializer added in v0.1.9

type TemplateInitializer interface {
	Init(*plates.Factory) error
}

Jump to

Keyboard shortcuts

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