Version: v1.0.3 Latest Latest

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





This section is empty.


This section is empty.


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.

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



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.

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"}))


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.


Path Synopsis

Jump to

Keyboard shortcuts

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