input

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultServiceTodo = false
)

Variables

This section is empty.

Functions

func ValidateConstructorType

func ValidateConstructorType(s Service) error

ValidateConstructorType validates whether the given service has a proper constructor. To initialize a service, it must have either a valid constructor or a value.

func ValidateDecoratorArgs

func ValidateDecoratorArgs(d Decorator) error

func ValidateDecoratorMethod

func ValidateDecoratorMethod(d Decorator) error

func ValidateDecoratorTag

func ValidateDecoratorTag(d Decorator) error

func ValidateDecorators

func ValidateDecorators(i Input) error

func ValidateMeta

func ValidateMeta(i Input) error

func ValidateMetaContainerConstructor

func ValidateMetaContainerConstructor(m Meta) error

func ValidateMetaContainerType

func ValidateMetaContainerType(m Meta) error

func ValidateMetaFunctions

func ValidateMetaFunctions(m Meta) error

func ValidateMetaImports

func ValidateMetaImports(m Meta) error

func ValidateMetaPkg

func ValidateMetaPkg(m Meta) error

func ValidateParams

func ValidateParams(i Input) error

func ValidateServiceArgs

func ValidateServiceArgs(s Service) error

func ValidateServiceCalls

func ValidateServiceCalls(s Service) error

func ValidateServiceConstructor

func ValidateServiceConstructor(s Service) error

func ValidateServiceFields

func ValidateServiceFields(s Service) error

func ValidateServiceGetter

func ValidateServiceGetter(s Service) error

func ValidateServiceName

func ValidateServiceName(n string) error

func ValidateServiceTags

func ValidateServiceTags(s Service) error

func ValidateServiceType

func ValidateServiceType(s Service) error

func ValidateServiceValue

func ValidateServiceValue(s Service) error

func ValidateServices

func ValidateServices(i Input) error

Types

type Call

type Call struct {
	Method    string
	Args      []any
	Immutable bool
}

func (*Call) UnmarshalYAML

func (c *Call) UnmarshalYAML(unmarshal func(interface{}) error) error

type Decorator

type Decorator struct {
	Tag       string `yaml:"tag"`       // http-client
	Decorator string `yaml:"decorator"` // myImport/pkgCopy.MakeTracedHttpClient
	Args      []any  `yaml:"arguments"` // ["@logger"]
}

type Input

type Input struct {
	Version    *Version           `yaml:"version"`
	Meta       Meta               `yaml:"meta"`
	Params     map[string]any     `yaml:"parameters"`
	Services   map[string]Service `yaml:"services"`
	Decorators []Decorator        `yaml:"decorators"`
}

func Merge

func Merge(i1, i2 Input) Input

type Meta

type Meta struct {
	Pkg                  *string           `yaml:"pkg"`                   // default "main"
	ContainerType        *string           `yaml:"container_type"`        // default "Gontainer"
	ContainerConstructor *string           `yaml:"container_constructor"` // default "NewGontainer"
	DefaultMustGetter    *bool             `yaml:"default_must_getter"`   // default false
	Imports              map[string]string `yaml:"imports"`               // {"alias": "my/long/path", ...}
	Functions            map[string]string `yaml:"functions"`             // {"env": "os.Getenv", ...}
}

type Scope

type Scope uint
const (
	ScopeShared Scope = iota + 1
	ScopeContextual
	ScopeNonShared
)

func (Scope) String

func (s Scope) String() string

func (*Scope) UnmarshalYAML

func (s *Scope) UnmarshalYAML(unmarshal func(interface{}) error) error

type Service

type Service struct {
	Getter      *string        `yaml:"getter"`      // e.g. GetDB
	MustGetter  *bool          `yaml:"must_getter"` // if true adds MustGet func, it requires non-empty Getter
	Type        *string        `yaml:"type"`        // *?my/import/path.Type
	Value       *string        `yaml:"value"`       // my/import/path.Variable
	Constructor *string        `yaml:"constructor"` // NewDB
	Args        []any          `yaml:"arguments"`   // ["%host%", "%port%", "@logger"]
	Calls       []Call         `yaml:"calls"`       // [["SetLogger", ["@logger"]], ...]
	Fields      map[string]any `yaml:"fields"`      // Field: "%value%"
	Tags        []Tag          `yaml:"tags"`        // ["service_decorator", ...]
	Scope       *Scope         `yaml:"scope"`       // scope for the service, if nil, default value will be applied
	Todo        *bool          `yaml:"todo"`        // if true skips validation and returns error whenever users asks container for a service
}

type Tag

type Tag struct {
	Name     string
	Priority int
}

func (*Tag) UnmarshalYAML

func (t *Tag) UnmarshalYAML(unmarshal func(interface{}) error) error

type ValidateFn

type ValidateFn func(Input) error

func DefaultDecoratorsValidators

func DefaultDecoratorsValidators() []ValidateFn

DefaultDecoratorsValidators returns validators for Input.Decorators.

func DefaultMetaValidators

func DefaultMetaValidators() []ValidateFn

DefaultMetaValidators returns validators for Input.Meta.

func DefaultParamsValidators

func DefaultParamsValidators() []ValidateFn

DefaultParamsValidators returns validators for Input.Params.

func DefaultServicesValidators

func DefaultServicesValidators() []ValidateFn

DefaultServicesValidators returns validators for Input.Services.

func DefaultVersionValidators

func DefaultVersionValidators(version string) []ValidateFn

DefaultVersionValidators returns validators for Input.Version.

type ValidateService

type ValidateService func(Service) error

type Validator

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

func NewDefaultValidator

func NewDefaultValidator(version string) *Validator

NewDefaultValidator expects a version that follows semver schema without the leading "v".

func NewValidator

func NewValidator(validators ...ValidateFn) *Validator

func (Validator) Validate

func (v Validator) Validate(m Input) error

type Version

type Version string

func (*Version) UnmarshalYAML

func (v *Version) UnmarshalYAML(unmarshal func(interface{}) error) error

type VersionValidator

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

func NewVersionValidator

func NewVersionValidator(version string) *VersionValidator

NewVersionValidator expects a proper version without the leading "v".

func (*VersionValidator) ValidateVersion

func (v *VersionValidator) ValidateVersion(i Input) (err error)

Jump to

Keyboard shortcuts

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