schema

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package schema the data structure definition

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSchema = errors.New("invalid schema")

ErrInvalidSchema invalid schema error

View Source
var ErrInvalidStep = errors.New("invalid step")

ErrInvalidStep invalid step error

Functions

This section is empty.

Types

type Action

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

Action The Schema Action

func NewAction

func NewAction(step ...Step) Action

NewAction returns a new Action with the given Step

func NewActionOp

func NewActionOp(op Operator) Action

NewActionOp returns a new Action with the given Operator

func (Action) MarshalYAML

func (a Action) MarshalYAML() (any, error)

MarshalYAML encodes the action to yaml

type Actions

type Actions []Action

Actions slice of Action

func (*Actions) GetElement

func (a *Actions) GetElement(ctx *parser.Context, content any) (string, error)

GetElement run the action returns an element string

func (*Actions) GetElements

func (a *Actions) GetElements(ctx *parser.Context, content any) ([]string, error)

GetElements run the action returns a slice of element string

func (*Actions) GetString

func (a *Actions) GetString(ctx *parser.Context, content any) (string, error)

GetString run the action returns a string

func (*Actions) GetStrings

func (a *Actions) GetStrings(ctx *parser.Context, content any) ([]string, error)

GetStrings run the action returns a slice of string

func (*Actions) UnmarshalYAML

func (a *Actions) UnmarshalYAML(value *yaml.Node) (err error)

UnmarshalYAML decodes the Action from yaml

type Model

type Model struct {
	Source *Source `yaml:"source"`
	Schema *Schema `yaml:"schema"`
}

Model the model

type Operator

type Operator string

Operator The Action operator.

const (
	// OperatorNil The Operator of nil.
	OperatorNil Operator = ""
	// OperatorAnd The Operator of and.
	// Action result A, B; Join the A + B.
	OperatorAnd Operator = "and"
	// OperatorOr The Operator of or.
	// Action result A, B; if result A is nil return B.
	OperatorOr Operator = "or"
)

type Property

type Property map[string]Schema

Property The Schema property.

type Schema

type Schema struct {
	Type       Type     `yaml:"type"`
	Format     Type     `yaml:"format,omitempty"`
	Init       Actions  `yaml:"init,omitempty"`
	Rule       Actions  `yaml:"rule,omitempty"`
	Properties Property `yaml:"properties,omitempty"`
}

Schema The schema.

func NewSchema

func NewSchema(types ...Type) *Schema

NewSchema returns a new Schema with the given Type. The first argument is the Schema.Type, second is the Schema.Format.

func (*Schema) AddInit

func (schema *Schema) AddInit(step ...Step) *Schema

AddInit append Step to Schema.Init.

func (*Schema) AddInitOp

func (schema *Schema) AddInitOp(op Operator) *Schema

AddInitOp append Operator to Schema.Init.

func (*Schema) AddProperty

func (schema *Schema) AddProperty(field string, s Schema) *Schema

AddProperty append a field string with Schema to Schema.Properties.

func (*Schema) AddRule

func (schema *Schema) AddRule(step ...Step) *Schema

AddRule append Step to Schema.Init.

func (*Schema) AddRuleOp

func (schema *Schema) AddRuleOp(op Operator) *Schema

AddRuleOp append Operator to Schema.Rule.

func (*Schema) CloneWithType

func (schema *Schema) CloneWithType(typ Type) *Schema

CloneWithType returns a copy of Schema. Schema.Format and Schema.Rule will be copied.

func (*Schema) MarshalYAML

func (schema *Schema) MarshalYAML() (any, error)

MarshalYAML encodes the Schema

func (*Schema) SetInit

func (schema *Schema) SetInit(action []Action) *Schema

SetInit set the Init Action to Schema.Init.

func (*Schema) SetProperty

func (schema *Schema) SetProperty(m Property) *Schema

SetProperty set the Property to Schema.Properties.

func (*Schema) SetRule

func (schema *Schema) SetRule(action []Action) *Schema

SetRule set the Init Action to Schema.Rule.

func (*Schema) UnmarshalYAML

func (schema *Schema) UnmarshalYAML(node *yaml.Node) (err error)

UnmarshalYAML decodes the Schema from yaml

type Source

type Source struct {
	Name    string        `yaml:"name"`
	HTTP    string        `yaml:"http"`
	Proxy   []string      `yaml:"proxy"`
	Timeout time.Duration `yaml:"timeout"`
}

Source the Model source

type Step

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

Step The Action of step

func NewStep

func NewStep(parser string, rule string) Step

NewStep returns a new Step with the given params

func (Step) MarshalYAML

func (s Step) MarshalYAML() (any, error)

MarshalYAML encodes to yaml

type Type

type Type string

Type The property type.

const (
	// StringType The Type of string.
	StringType Type = "string"
	// NumberType The Type of number.
	NumberType Type = "number"
	// IntegerType The Type of integer.
	IntegerType Type = "integer"
	// BooleanType The Type of boolean.
	BooleanType Type = "boolean"
	// ObjectType The Type of object.
	ObjectType Type = "object"
	// ArrayType The Type of array.
	ArrayType Type = "array"
)

func ToType

func ToType(s any) (Type, error)

ToType parses the schema type.

Jump to

Keyboard shortcuts

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