validator

package
Version: v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(descriptor map[string]interface{}, profile string, registry Registry) error

Validate checks whether the descriptor the descriptor is valid against the passed-in profile/registry. If the validation process generates multiple errors, their messages are coalesced. It is a syntax-sugar around getting the validator from the registry and coalescing errors.

Example
resource := map[string]interface{}{"name": "foo", "path": "foo.csv"}
fmt.Print(Validate(resource, "data-resource", MustInMemoryRegistry()))
Output:

<nil>

Types

type DescriptorValidator

type DescriptorValidator interface {
	Validate(map[string]interface{}) error
}

DescriptorValidator validates a Data-Package or Resource descriptor.

func New

func New(profile string, loaders ...RegistryLoader) (DescriptorValidator, error)

New returns a new descriptor validator for the passed-in profile.

type Registry

type Registry interface {
	GetValidator(profile string) (DescriptorValidator, error)
}

Registry represents a set of registered validators, which could be loaded locally or remotelly.

func MustInMemoryRegistry

func MustInMemoryRegistry() Registry

MustInMemoryRegistry returns the local cache registry, which is shipped with the library. It panics if there are errors retrieving the registry.

func NewRegistry

func NewRegistry(loaders ...RegistryLoader) (Registry, error)

NewRegistry returns a registry where users could get descriptor validators.

Example
registry, _ := NewRegistry(LocalRegistryLoader(localRegistryPath, true /* in memory only*/))
validator, _ := registry.GetValidator("data-resource")
fmt.Println(validator.Validate(map[string]interface{}{"name": "res1", "path": "foo.csv"}))
Output:

<nil>

type RegistryLoader

type RegistryLoader func() (Registry, error)

RegistryLoader loads a registry.

func FallbackRegistryLoader

func FallbackRegistryLoader(loaders ...RegistryLoader) RegistryLoader

FallbackRegistryLoader returns the first passed-in registry loaded successfully. It returns an error if there is no successfully loaded registry.

func InMemoryLoader

func InMemoryLoader() RegistryLoader

InMemoryLoader returns a loader which points tothe local cache registry.

func LocalRegistryLoader

func LocalRegistryLoader(localRegistryPath string, inMemoryOnly bool) RegistryLoader

LocalRegistryLoader creates a new registry, which is based on the local file system (or in-memory cache) to locate json schema profiles. Setting inMemoryOnly to true will make sure only the in-memory cache (registry_cache Go package) is accessed, thus avoiding access the filesystem.

func RemoteRegistryLoader

func RemoteRegistryLoader(url string) RegistryLoader

RemoteRegistryLoader loads the schema registry map from the passed-in URL.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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