datapackage-go: Index | Examples | Files | Directories

package validator

import ""



Package Files

jsonschema.go registry.go validator.go

func Validate Uses

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 Uses

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

DescriptorValidator validates a Data-Package or Resource descriptor.

func New Uses

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

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

type Registry Uses

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

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

func MustInMemoryRegistry Uses

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 Uses

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 Uses

type RegistryLoader func() (Registry, error)

RegistryLoader loads a registry.

func FallbackRegistryLoader Uses

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 Uses

func InMemoryLoader() RegistryLoader

InMemoryLoader returns a loader which points tothe local cache registry.

func LocalRegistryLoader Uses

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 Uses

func RemoteRegistryLoader(url string) RegistryLoader

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



Package validator imports 10 packages (graph) and is imported by 1 packages. Updated 2018-04-20. Refresh now. Tools for package owners.