state

package
v0.10.9 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SetMarkerTag      = `setMarker:"true" format:"-" sqlx:"-" diff:"-" json:"-" `
	TypedSetMarkerTag = SetMarkerTag + ` typeName:"%s"`
)

Variables

This section is empty.

Functions

func AsCodecOptions

func AsCodecOptions(options []interface{}) []codec.Option

AsCodecOptions creates codec options

func BuildCodec

func BuildCodec(aTag *tags.Tag, param *Parameter)

func BuildHandler

func BuildHandler(aTag *tags.Tag, param *Parameter)

func BuildPredicate

func BuildPredicate(aTag *tags.Tag, param *Parameter)

func BuildSchema

func BuildSchema(field *reflect.StructField, pTag *tags.Parameter, result *Parameter, lookupType xreflect.LookupType)

func IsReservedAsyncState

func IsReservedAsyncState(name string) bool

IsReservedAsyncState returns true if reserved async state

func NewField

func NewField(aTag string, structFieldName string, rType reflect.Type) reflect.StructField

func PkgPath

func PkgPath(fieldName string, pkgPath string) (fieldPath string)

func RawComponentType

func RawComponentType(typeName string) string

func SanitizeTypeName

func SanitizeTypeName(typeName string) string

func StructFieldName

func StructFieldName(sourceCaseFormat text.CaseFormat, columnName string) string

Types

type Cardinality

type Cardinality string
const (
	One  Cardinality = "One"
	Many Cardinality = "Many"
)

type Codec

type Codec struct {
	shared.Reference
	Name       string   `json:",omitempty" yaml:"Name,omitempty" `
	Body       string   `json:",omitempty" yaml:"Body,omitempty"`
	Args       []string `json:",omitempty" yaml:"Args,omitempty"`
	Schema     *Schema  `json:",omitempty" yaml:"Schema,omitempty"`
	OutputType string   `json:",omitempty" yaml:"OutputType,omitempty"`
	// contains filtered or unexported fields
}

func NewCodec

func NewCodec(name string, schema *Schema, instance codec.Instance) *Codec

func (*Codec) Init

func (v *Codec) Init(resource Resource, inputType reflect.Type) error

func (*Codec) Initialized

func (v *Codec) Initialized() bool

func (*Codec) Transform

func (v *Codec) Transform(ctx context.Context, value interface{}, options ...codec.Option) (interface{}, error)

type Docs

type Docs struct {
	Filter     Documentation
	Columns    Documentation
	Parameters Documentation
	Paths      Documentation
}

func (*Docs) Merge added in v0.10.0

func (d *Docs) Merge(from *Docs)

type Documentation

type Documentation map[string]interface{}

func (Documentation) ByName

func (d Documentation) ByName(name string) (string, bool)

func (Documentation) ColumnDescription added in v0.10.0

func (d Documentation) ColumnDescription(table, column string) (string, bool)

func (Documentation) ColumnExample added in v0.10.0

func (d Documentation) ColumnExample(table, column string) (string, bool)

func (Documentation) FieldDocumentation

func (d Documentation) FieldDocumentation(name string) (Documentation, bool)

func (Documentation) Merge added in v0.10.0

func (d Documentation) Merge(output Documentation)

type Embedder added in v0.9.14

type Embedder interface {
	EmbedFS() *embed.FS
}

Embedder represents embedder

type FSEmbedder added in v0.9.14

type FSEmbedder struct {
	// contains filtered or unexported fields
}

FSEmbedder represents fs embedder

func NewFSEmbedder added in v0.9.14

func NewFSEmbedder(fs *embed.FS) *FSEmbedder

func (*FSEmbedder) EmbedFS added in v0.9.14

func (f *FSEmbedder) EmbedFS() *embed.FS

EmbedFS returns embed fs

func (*FSEmbedder) SetType added in v0.9.14

func (f *FSEmbedder) SetType(rType reflect.Type) bool

SetType sets type

type Finalizer

type Finalizer interface {
	Finalize(ctx context.Context) error
}

Finalizer is an interface that should be implemented by any type that needs to be finalized

type Handler

type Handler struct {
	Name string   `tag:"name,omitempty"`
	Args []string `tag:"arguments,omitempty"`
}

Handler represents a handler

type Initializer

type Initializer interface {
	Init(ctx context.Context) error
}

Initializer is an interface that should be implemented by any type that needs to be initialized

type Kind

type Kind string

Kind represents parameter location Parameter value can be retrieved from the i.e. HTTP Header, path Variable or using other View

const (
	KindView        Kind = "view"
	KindHeader      Kind = "header"
	KindQuery       Kind = "query"
	KindForm        Kind = "form"
	KindPath        Kind = "path"
	KindCookie      Kind = "cookie"
	KindRequestBody Kind = "body"
	KindEnvironment Kind = "env"
	KindConst       Kind = "const"
	KindLiteral     Kind = "literal"

	KindParam   Kind = "param"
	KindRequest Kind = "http_request"
	KindObject  Kind = "object"

	KindRepeated Kind = "repeated"

	KindOutput Kind = "output" //reader output

	KindAsync Kind = "async" //async jobs/status related information

	KindMeta Kind = "meta" //component/view meta information

	KindState     Kind = "state"     //input state
	KindComponent Kind = "component" //input state
	KindContext   Kind = "context"   //global context based state

	//KindGenerator represents common value generator
	KindGenerator Kind = "generator"

	//KindTransient represents parameter placeholder with no actual value source
	KindTransient Kind = "transient"

	//KindHandler represents handler type
	KindHandler Kind = "handler"
)

func (Kind) Ordinal

func (k Kind) Ordinal() int

func (Kind) Validate

func (k Kind) Validate() error

Validate checks if Kind is valid.

type Location

type Location struct {
	Kind Kind   `json:",omitempty" yaml:"Kind"`
	Name string `json:",omitempty" yaml:"Name"`
}

Location represents parameter location

func NewBodyLocation

func NewBodyLocation(name string) *Location

NewBodyLocation creates a body location

func NewComponent

func NewComponent(name string) *Location

NewComponent creates a component location

func NewConstLocation

func NewConstLocation(name string) *Location

func NewContextLocation

func NewContextLocation(name string) *Location

NewContextLocation creates a context location

func NewFormLocation

func NewFormLocation(name string) *Location

NewFormLocation creates a query location

func NewGenerator

func NewGenerator(name string) *Location

NewGenerator creates a generator kind

func NewHeaderLocation

func NewHeaderLocation(name string) *Location

NewHeaderLocation creates a query location

func NewObjectLocation

func NewObjectLocation(name string) *Location

NewObjectLocation creates an output location

func NewOutputLocation

func NewOutputLocation(name string) *Location

NewOutputLocation creates an output location

func NewParameterLocation

func NewParameterLocation(name string) *Location

NewParameterLocation creates a parameter location

func NewPathLocation

func NewPathLocation(name string) *Location

NewPathLocation creates a path location

func NewQueryLocation

func NewQueryLocation(name string) *Location

NewQueryLocation creates a query location

func NewRequestLocation

func NewRequestLocation() *Location

NewRequestLocation creates a body location

func NewState

func NewState(name string) *Location

NewState creates a state location

func NewViewLocation

func NewViewLocation(name string) *Location

NewViewLocation creates a dataview location

func (*Location) IsView

func (l *Location) IsView() bool

func (*Location) Validate

func (l *Location) Validate() error

Validate checks if Location is valid

type NamedParameters

type NamedParameters map[string]*Parameter

NamedParameters represents Parameter map indexed by Parameter.Name

func (NamedParameters) Lookup

func (p NamedParameters) Lookup(name string) (*Parameter, error)

Lookup returns Parameter with given name

func (NamedParameters) LookupByLocation

func (s NamedParameters) LookupByLocation(kind Kind, location string) *Parameter

func (NamedParameters) Merge

func (p NamedParameters) Merge(with NamedParameters)

func (NamedParameters) Register

func (p NamedParameters) Register(parameter *Parameter) error

Register registers parameter

type Option

type Option func(t *Type)

func WithBodyType

func WithBodyType(bodyType bool) Option

func WithDoc

func WithDoc(doc Documentation) Option

func WithFS

func WithFS(fs *embed.FS) Option

func WithMarker

func WithMarker(marker bool) Option

func WithPackage

func WithPackage(pkg string) Option

func WithParameters

func WithParameters(parameters Parameters) Option

func WithResource

func WithResource(resource Resource) Option

func WithSchema

func WithSchema(schema *Schema) Option

type ParamName

type ParamName string

ParamName represents name of parameter in given Location.Kind i.e. if you want to extract lang from query string: ?foo=bar&lang=eng required Kind is KindQuery and ParamName `lang`

func (ParamName) Validate

func (p ParamName) Validate(kind Kind) error

Validate checks if ParamName is valid

type Parameter

type Parameter struct {
	shared.Reference
	Object   Parameters `json:",omitempty" yaml:"Object"`
	Repeated Parameters `json:",omitempty" yaml:"Repeated"`

	//LocationInput, component input
	LocationInput *Type `json:",omitempty" yaml:"Input"`

	Predicates        []*extension.PredicateConfig `json:",omitempty" yaml:"Predicates"`
	Name              string                       `json:",omitempty" yaml:"Name"`
	SQL               string                       `json:",omitempty" yaml:"SQL"`
	In                *Location                    `json:",omitempty" yaml:"In" `
	Scope             string                       `json:",omitempty" yaml:"Scope" `
	Required          *bool                        `json:",omitempty"  yaml:"Required" `
	Description       string                       `json:",omitempty" yaml:"Description"`
	Example           string                       `json:",omitempty" yaml:"Example"`
	Style             string                       `json:",omitempty" yaml:"Style"`
	MaxAllowedRecords *int                         `json:",omitempty"`
	MinAllowedRecords *int                         `json:",omitempty"`
	ExpectedReturned  *int                         `json:",omitempty"`
	Schema            *Schema                      `json:",omitempty" yaml:"Schema"`
	Output            *Codec                       `json:",omitempty" yaml:"Output"`
	Handler           *Handler                     `json:",omitempty" yaml:"Handler"`
	Value             interface{}                  `json:"Value,omitempty" yaml:"Value"`
	//deprecated use format timelayout instead
	DateFormat      string `json:",omitempty" yaml:"DateFormat"`
	ErrorStatusCode int    `json:",omitempty" yaml:"ErrorStatusCode"`
	ErrorMessage    string `json:",omitempty" yaml:"ErrorMessage"`
	Tag             string `json:",omitempty" yaml:"Tag"`
	When            string `json:",omitempty" yaml:"When"`
	With            string `json:",omitempty" yaml:"With"`
	Cacheable       *bool  `json:",omitempty" yaml:"Cacheable"`
	Async           bool   `json:",omitempty" yaml:"Async"`
	// contains filtered or unexported fields
}

func BuildParameter

func BuildParameter(field *reflect.StructField, fs *embed.FS, lookupType xreflect.LookupType) (*Parameter, error)

func NewParameter

func NewParameter(name string, in *Location, opts ...ParameterOption) *Parameter

NewParameter creates a parameter

func NewRefParameter

func NewRefParameter(name string) *Parameter

NewRefParameter creates a new ref parameter

func (*Parameter) Clone

func (p *Parameter) Clone() *Parameter

func (*Parameter) CombineTags

func (p *Parameter) CombineTags() reflect.StructTag

func (*Parameter) GetValue

func (p *Parameter) GetValue(state *structology.State) (interface{}, error)

func (*Parameter) Init

func (p *Parameter) Init(ctx context.Context, resource Resource) error

Init initializes Parameter

func (*Parameter) IsAnonymous added in v0.9.6

func (p *Parameter) IsAnonymous() bool

func (*Parameter) IsAsync added in v0.9.4

func (p *Parameter) IsAsync() bool

func (*Parameter) IsCacheable

func (p *Parameter) IsCacheable() bool

func (*Parameter) IsHTTPParameter added in v0.10.0

func (p *Parameter) IsHTTPParameter() bool

func (*Parameter) IsRequired

func (p *Parameter) IsRequired() bool

func (*Parameter) IsUsedBy

func (p *Parameter) IsUsedBy(text string) bool

func (*Parameter) NewState

func (p *Parameter) NewState(value interface{}) *structology.State

func (*Parameter) OutputSchema

func (p *Parameter) OutputSchema() *Schema

func (*Parameter) OutputType

func (p *Parameter) OutputType() reflect.Type

func (*Parameter) Selector

func (p *Parameter) Selector() *structology.Selector

func (*Parameter) Set

func (p *Parameter) Set(state *structology.State, value interface{}) error

func (*Parameter) SetSelector

func (p *Parameter) SetSelector(selector *structology.Selector)

func (*Parameter) SetTypeNameTag

func (p *Parameter) SetTypeNameTag()

func (*Parameter) Validate

func (p *Parameter) Validate() error

Validate checks if parameter is valid

type ParameterOption

type ParameterOption func(p *Parameter)

func WithCacheable added in v0.9.7

func WithCacheable(flag bool) ParameterOption

func WithParameterSchema

func WithParameterSchema(schema *Schema) ParameterOption

func WithParameterTag

func WithParameterTag(tag string) ParameterOption

func WithParameterType

func WithParameterType(t reflect.Type) ParameterOption

WithParameterType returns schema type parameter option

type Parameters

type Parameters []*Parameter

Parameters represents slice of parameters

func (*Parameters) Append

func (p *Parameters) Append(parameter *Parameter)

Append appends parameter

func (Parameters) BuildBodyType

func (p Parameters) BuildBodyType(pkgPath string, lookupType xreflect.LookupType) (reflect.Type, error)

func (Parameters) ByKindName added in v0.9.7

func (p Parameters) ByKindName() NamedParameters

ByKindName indexes parameters by Parameter.In.Name

func (Parameters) External

func (p Parameters) External() Parameters

func (Parameters) Filter

func (p Parameters) Filter(kind Kind) NamedParameters

Filter filters Parameters with given Kind and creates Template

func (Parameters) FilterByKind

func (p Parameters) FilterByKind(kind Kind) Parameters

func (Parameters) FlagOutput

func (p Parameters) FlagOutput()

func (Parameters) Groups

func (p Parameters) Groups() []Parameters

func (Parameters) HasErrorParameter added in v0.9.2

func (p Parameters) HasErrorParameter() bool

func (Parameters) HttpParameters added in v0.10.0

func (p Parameters) HttpParameters() Parameters

func (Parameters) Index

func (p Parameters) Index() NamedParameters

Index indexes parameters by Parameter.Name

func (Parameters) InitRepeated

func (p Parameters) InitRepeated(state *structology.State) (err error)

func (Parameters) LocationInput

func (p Parameters) LocationInput() Parameters

LocationInput returns location input

func (Parameters) Lookup

func (p Parameters) Lookup(name string) *Parameter

Lookup returns match parameter or nil

func (Parameters) LookupByLocation

func (p Parameters) LookupByLocation(kind Kind, location string) *Parameter

LookupByLocation returns match parameter by location

func (Parameters) PredicateStructType

func (p Parameters) PredicateStructType() reflect.Type

func (Parameters) ReflectType

func (p Parameters) ReflectType(pkgPath string, lookupType xreflect.LookupType, opts ...ReflectOption) (reflect.Type, error)

func (Parameters) SetLiterals

func (p Parameters) SetLiterals(state *structology.State) (err error)

func (Parameters) UsedBy

func (p Parameters) UsedBy(text string) Parameters

type ReflectOption

type ReflectOption func(o *reflectOptions)

func WithLocationInput

func WithLocationInput(parameters Parameters) ReflectOption

func WithRelation

func WithRelation() ReflectOption

func WithSQL

func WithSQL() ReflectOption

func WithSetMarker

func WithSetMarker() ReflectOption

func WithTypeName

func WithTypeName(name string) ReflectOption

func WithVelty

func WithVelty(flag bool) ReflectOption

type Resource

type Resource interface {
	LookupParameter(name string) (*Parameter, error)

	AppendParameter(parameter *Parameter)
	ViewSchema(ctx context.Context, name string) (*Schema, error)
	ViewSchemaPointer(ctx context.Context, name string) (*Schema, error)
	LookupType() xreflect.LookupType
	LoadText(ctx context.Context, URL string) (string, error)
	Codecs() *codec.Registry
	//CodecOptions returns base codec options
	CodecOptions() *codec.Options

	ExpandSubstitutes(text string) string

	ReverseSubstitutes(text string) string
}

type Schema

type Schema struct {
	Package     string      `json:",omitempty" yaml:"Package,omitempty"`
	PackagePath string      `json:",omitempty" yaml:"PackagePath,omitempty"`
	ModulePath  string      `json:",omitempty" yaml:"ModulePath,omitempty"`
	Name        string      `json:",omitempty" yaml:"Name,omitempty"`
	DataType    string      `json:",omitempty" yaml:"DataType,omitempty"`
	Cardinality Cardinality `json:",omitempty" yaml:"Cardinality,omitempty"`
	Methods     []reflect.Method
	// contains filtered or unexported fields
}

Schema represents View as Go type.

func EmptySchema

func EmptySchema() *Schema

EmptySchema returns empty struct schema

func NewSchema

func NewSchema(compType reflect.Type, opts ...SchemaOption) *Schema

func (*Schema) AutoGen

func (s *Schema) AutoGen() bool

AutoGen indicates whether Schema was generated using ColumnTypes fetched from DB or was passed programmatically.

func (*Schema) Clone

func (s *Schema) Clone() *Schema

func (*Schema) CompType

func (s *Schema) CompType() reflect.Type

CompType returns component type

func (*Schema) EnsurePointer

func (s *Schema) EnsurePointer()

func (*Schema) GetPackage added in v0.9.8

func (s *Schema) GetPackage() string

func (*Schema) InheritType

func (s *Schema) InheritType(rType reflect.Type)

func (*Schema) Init

func (s *Schema) Init(resource Resource) error

Init build struct type

func (*Schema) InitType

func (s *Schema) InitType(lookupType xreflect.LookupType, ptr bool) error

func (*Schema) IsNamed

func (s *Schema) IsNamed() bool

IsNamed returns true if compiled named type is used

func (*Schema) IsStruct

func (s *Schema) IsStruct() bool

func (*Schema) LoadTypeIfNeeded

func (s *Schema) LoadTypeIfNeeded(lookupType xreflect.LookupType) error

func (*Schema) SetPackage

func (s *Schema) SetPackage(pkg string)

func (*Schema) SetType

func (s *Schema) SetType(rType reflect.Type)

SetType sets Types

func (*Schema) SimpleTypeName

func (s *Schema) SimpleTypeName() string

func (*Schema) Slice

func (s *Schema) Slice() *xunsafe.Slice

Slice returns slice as xunsafe.Slice

func (*Schema) SliceType

func (s *Schema) SliceType() reflect.Type

SliceType returns reflect.SliceOf() Schema type

func (*Schema) Type

func (s *Schema) Type() reflect.Type

Type returns struct type

func (*Schema) TypeName

func (s *Schema) TypeName() string

type SchemaOption

type SchemaOption func(s *Schema)

Schema represents View as Go type.

func WithAutoGenFlag

func WithAutoGenFlag(flag bool) SchemaOption

WithAutoGenFlag creates with autogen schema option

func WithAutoGenFunc

func WithAutoGenFunc(fn func() (reflect.Type, error)) SchemaOption

WithAutoGenFunc return autoget

func WithMany

func WithMany() SchemaOption

func WithModulePath

func WithModulePath(aPath string) SchemaOption

func WithPackagePath added in v0.9.8

func WithPackagePath(pkgPath string) SchemaOption

WithPackagePath returns package options

func WithSchemaMethods

func WithSchemaMethods(methods []reflect.Method) SchemaOption

func WithSchemaPackage

func WithSchemaPackage(pkg string) SchemaOption

type Type

type Type struct {
	*Schema
	Parameters Parameters `json:",omitempty" yaml:"Parameters"`

	Doc Documentation
	// contains filtered or unexported fields
}

Type represents parameters/schema derived state type

func NewType

func NewType(option ...Option) (*Type, error)

func (*Type) AnonymousParameters

func (t *Type) AnonymousParameters() *Parameter

func (*Type) Init

func (t *Type) Init(options ...Option) (err error)

func (*Type) IsAnonymous

func (t *Type) IsAnonymous() bool

IsAnonymous returns flag for basic unwrapped style

func (*Type) SetType

func (t *Type) SetType(rType reflect.Type)

func (*Type) Type

func (t *Type) Type() *structology.StateType

Type returns structorlogy state

type Types

type Types struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTypes

func NewTypes() *Types

func (*Types) Lookup

func (c *Types) Lookup(p reflect.Type) (*Type, bool)

func (*Types) Put

func (c *Types) Put(t *Type)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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