schema

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

README ¶

schema

Github template for new libraries

Static Badge

GoDoc GitHub stars Go Report Card codecov

Versions

Stable Version GitHub Release GitHub Release

Introduction

This is template repository for new libraries

Important

  • Edit go.mod and rename to your package module
  • Uncomment .github/workflows/tests.yml

Contributing

Read Contributing

Contributors

JanGalek actions-user

Join our Discord Community! 🎉

Discord

Click above to join our community on Discord!

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func CastTo ¶

func CastTo[T any](data map[string]any, v *T) error

func Normalize ¶

func Normalize(data any) (any, error)

Normalize function to clean and prepare data

func Process ¶

func Process(schema Field, data any, mergeDefaults bool) (any, error)

Process function with normalization for handling defaults

Types ¶

type AnyOfField ¶

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

AnyOfField for anyOf

func (*AnyOfField) CastTo ¶

func (a *AnyOfField) CastTo(target any) (any, error)

func (*AnyOfField) Default ¶

func (a *AnyOfField) Default(value any) Field

func (*AnyOfField) GetDefault ¶

func (a *AnyOfField) GetDefault() any

func (*AnyOfField) HasDefault ¶

func (a *AnyOfField) HasDefault() bool

func (*AnyOfField) IsRequired ¶

func (a *AnyOfField) IsRequired() bool

func (*AnyOfField) Required ¶

func (a *AnyOfField) Required() Field

func (*AnyOfField) Validate ¶

func (a *AnyOfField) Validate(value any) error

type ArrayField ¶

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

ArrayField for handling slices

func (*ArrayField) CastTo ¶

func (a *ArrayField) CastTo(target any) (any, error)

func (*ArrayField) Default ¶

func (a *ArrayField) Default(value any) Field

func (*ArrayField) GetDefault ¶

func (a *ArrayField) GetDefault() any

func (*ArrayField) HasDefault ¶

func (a *ArrayField) HasDefault() bool

func (*ArrayField) IsRequired ¶

func (a *ArrayField) IsRequired() bool

func (*ArrayField) Required ¶

func (a *ArrayField) Required() Field

func (*ArrayField) Validate ¶

func (a *ArrayField) Validate(value any) error

type BoolField ¶

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

func (*BoolField) CastTo ¶

func (b *BoolField) CastTo(target any) (any, error)

func (*BoolField) Default ¶

func (b *BoolField) Default(value any) Field

func (*BoolField) GetDefault ¶

func (b *BoolField) GetDefault() any

func (*BoolField) HasDefault ¶

func (b *BoolField) HasDefault() bool

func (*BoolField) IsRequired ¶

func (b *BoolField) IsRequired() bool

func (*BoolField) Required ¶

func (b *BoolField) Required() Field

func (*BoolField) Validate ¶

func (b *BoolField) Validate(value any) error

type Field ¶

type Field interface {
	Validate(value any) error
	Default(value any) Field
	CastTo(target any) (any, error)
	HasDefault() bool
	GetDefault() any
	Required() Field
	IsRequired() bool
}

func AnyOf ¶

func AnyOf(types ...Field) Field

func Array ¶

func Array(elem Field) Field

func ArrayOf ¶

func ArrayOf(elem Field) Field

func Bool ¶

func Bool() Field

func Float ¶

func Float() Field

func FromStruct ¶

func FromStruct(v any) (Field, error)

func Int ¶

func Int() Field

func ListOf ¶

func ListOf(elem Field) Field

func Map ¶

func Map(keyType, valueType Field) Field

func String ¶

func String() Field

func Structure ¶

func Structure(fields map[string]Field) Field

type FloatField ¶

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

func (*FloatField) CastTo ¶

func (f *FloatField) CastTo(target any) (any, error)

func (*FloatField) Default ¶

func (f *FloatField) Default(value any) Field

func (*FloatField) GetDefault ¶

func (f *FloatField) GetDefault() any

func (*FloatField) HasDefault ¶

func (f *FloatField) HasDefault() bool

func (*FloatField) IsRequired ¶

func (f *FloatField) IsRequired() bool

func (*FloatField) Required ¶

func (f *FloatField) Required() Field

func (*FloatField) Validate ¶

func (f *FloatField) Validate(value any) error

type IntField ¶

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

func (*IntField) CastTo ¶

func (i *IntField) CastTo(target any) (any, error)

func (*IntField) Default ¶

func (i *IntField) Default(value any) Field

func (*IntField) GetDefault ¶

func (i *IntField) GetDefault() any

func (*IntField) HasDefault ¶

func (i *IntField) HasDefault() bool

func (*IntField) IsRequired ¶

func (i *IntField) IsRequired() bool

func (*IntField) Required ¶

func (i *IntField) Required() Field

func (*IntField) Validate ¶

func (i *IntField) Validate(value any) error

type ListField ¶

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

ListField for listOf (indexed arrays)

func (*ListField) CastTo ¶

func (l *ListField) CastTo(target any) (any, error)

func (*ListField) Default ¶

func (l *ListField) Default(value any) Field

func (*ListField) GetDefault ¶

func (l *ListField) GetDefault() any

func (*ListField) HasDefault ¶

func (l *ListField) HasDefault() bool

func (*ListField) IsRequired ¶

func (l *ListField) IsRequired() bool

func (*ListField) Required ¶

func (l *ListField) Required() Field

func (*ListField) Validate ¶

func (l *ListField) Validate(value any) error

type MapField ¶

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

MapField for handling maps

func (*MapField) CastTo ¶

func (m *MapField) CastTo(target any) (any, error)

func (*MapField) Default ¶

func (m *MapField) Default(value any) Field

func (*MapField) GetDefault ¶

func (m *MapField) GetDefault() any

func (*MapField) HasDefault ¶

func (m *MapField) HasDefault() bool

func (*MapField) IsRequired ¶

func (m *MapField) IsRequired() bool

func (*MapField) Required ¶

func (m *MapField) Required() Field

func (*MapField) Validate ¶

func (m *MapField) Validate(value any) error

type StringField ¶

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

func (*StringField) CastTo ¶

func (s *StringField) CastTo(target any) (any, error)

func (*StringField) Default ¶

func (s *StringField) Default(value any) Field

func (*StringField) GetDefault ¶

func (s *StringField) GetDefault() any

func (*StringField) HasDefault ¶

func (s *StringField) HasDefault() bool

func (*StringField) IsRequired ¶

func (s *StringField) IsRequired() bool

func (*StringField) Required ¶

func (s *StringField) Required() Field

func (*StringField) Validate ¶

func (s *StringField) Validate(value any) error

type StructureField ¶

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

func (*StructureField) CastTo ¶

func (s *StructureField) CastTo(target any) (any, error)

func (*StructureField) Default ¶

func (s *StructureField) Default(value any) Field

func (*StructureField) GetDefault ¶

func (s *StructureField) GetDefault() any

func (*StructureField) HasDefault ¶

func (s *StructureField) HasDefault() bool

func (*StructureField) IsRequired ¶

func (s *StructureField) IsRequired() bool

func (*StructureField) Required ¶

func (s *StructureField) Required() Field

func (*StructureField) Validate ¶

func (s *StructureField) Validate(value any) error

Jump to

Keyboard shortcuts

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