documentloader

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrContextNotFound = errors.New("context not found")

ErrContextNotFound is returned when JSON-LD context document is not found in the underlying storage.

Functions

This section is empty.

Types

type DocumentLoader

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

DocumentLoader is an implementation of ld.DocumentLoader backed by storage.

func NewDocumentLoader

func NewDocumentLoader(ctx provider, opts ...Opts) (*DocumentLoader, error)

NewDocumentLoader returns a new DocumentLoader instance.

Embedded contexts (`ldcontext/embed/third_party`) are preloaded into the underlying storage. Additional contexts can be set using WithExtraContexts() option or provided by one or more remote providers. Use multiple WithRemoteProvider() options for setting up more than one remote JSON-LD context provider.

By default, missing contexts are not fetched from the remote URL. Use WithRemoteDocumentLoader() option to specify a custom loader that can resolve context documents from the network.

func (*DocumentLoader) LoadDocument

func (l *DocumentLoader) LoadDocument(u string) (*jsonld.RemoteDocument, error)

LoadDocument resolves JSON-LD context document by document URL (u) either from storage or from remote URL. If document is not found in the storage and remote DocumentLoader is not specified, ErrContextNotFound is returned.

type Opts

type Opts func(opts *documentLoaderOpts)

Opts configures DocumentLoader during creation.

func WithExtraContexts

func WithExtraContexts(contexts ...ldcontext.Document) Opts

WithExtraContexts sets the extra contexts (in addition to embedded) for preloading into the underlying storage.

func WithRemoteDocumentLoader

func WithRemoteDocumentLoader(loader jsonld.DocumentLoader) Opts

WithRemoteDocumentLoader specifies loader for fetching JSON-LD context documents from remote URLs. Documents are fetched with this loader only if they are not found in the underlying storage.

func WithRemoteProvider

func WithRemoteProvider(provider RemoteProvider) Opts

WithRemoteProvider adds a remote JSON-LD context provider to the list of providers.

type RemoteProvider

type RemoteProvider interface {
	Endpoint() string
	Contexts() ([]ldcontext.Document, error)
}

RemoteProvider defines a remote JSON-LD context provider.

Jump to

Keyboard shortcuts

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