validate

package
v0.0.0-...-ee364c6 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PointerToStringStruct

func PointerToStringStruct(ptr any) bool

Validates that the input is a pointer to a struct where all fields are strings.

func StructFromJSON

func StructFromJSON(value any) ([]string, error)

Finds any fields from the struct which are zero-valued. `value` must be a `struct` or its pointer. Accepted tags:

`json:"nameInJson"` -> maps JSON to struct fields when deserialising JSON
`optional:"true"` -> for JSONField only, allows field to not be set
`nullable:"true"` -> for JSONField only, allows field to be set to null
`zeroable:"true"` -> for JSONField only, allows field to be set to zero-value

Used to validate the deserialisation of a JSON document.

func UniqueList

func UniqueList[K comparable](list []K) bool

Types

type JSONField

type JSONField[T any] struct {
	Value  T
	IsNull bool
	IsSet  bool
}

Type wrapper used to validate the struct which a JSON document is unmarshaled to. Accepted tags:

`json:"nameInJson"` -> maps JSON to struct fields when deserialising JSON
`optional:"true"` -> allows field to not be set
`nullable:"true"` -> allows field to be set to null
`zeroable:"true"` -> allows field to be set to zero-value

func (*JSONField[any]) UnmarshalJSON

func (i *JSONField[any]) UnmarshalJSON(data []byte) error

this is called implicitly when unmarshalling into a struct containing JSONField

Jump to

Keyboard shortcuts

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