namespace

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

nolint:misspell

Package namespace provides support for managing namespaces for RDF or XML URIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

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

Service provides functionality to query and persist namespaces.

func NewService

func NewService(options ...ServiceOptionFunc) (*Service, error)

NewService creates a new client to work with namespaces.

NewService, by default, is meant to be long-lived and shared across your application.

The caller can configure the new service by passing configuration options to the func.

Example:

  service, err := namespace.NewService(
    namespace.WithDefaults(),
	 )

If no Store is configured, Service uses a in-memory store by default.

An error is also returned when some configuration option is invalid.

func (*Service) Add

func (s *Service) Add(prefix, base string) (*domain.NameSpace, error)

Add adds the prefix and base-URI to the namespace service. When either the prefix or the base-URI is already present in the service the unknown is stored as an alternative. If neither is present a new NameSpace is created.

func (*Service) Delete

func (s *Service) Delete(ns *domain.NameSpace) error

Delete removes a namespace from the store

func (*Service) Len

func (s *Service) Len() int

Len returns the number of namespaces in the Service

func (*Service) List

func (s *Service) List() ([]*domain.NameSpace, error)

List returns a list of all stored NameSpace objects. An error is returned when the underlying storage can't be accessed.

func (*Service) SearchLabel

func (s *Service) SearchLabel(uri string) (string, error)

SearchLabel returns the URI in a short namespaced form. The string is formatted as namespace prefix and label joined with an underscore, e.g. "dc_title".

The underscore is used instead of the more common colon because it mainly used as the search field in Lucene-based search engine, where it would conflict with the separator between the query-field and value.

func (*Service) Set

func (s *Service) Set(ns *domain.NameSpace) error

Set sets the default prefix and base-URI for a namespace. When the namespace is already present it will be overwritten. When the NameSpace contains an unknown prefix and base-URI pair but one of them is found in the NameSpace service, the current default is stored in PrefixAlt or BaseAlt and the new default set.

type ServiceOptionFunc

type ServiceOptionFunc func(*Service) error

ServiceOptionFunc is a function that configures a Service. It is used in NewService.

func SetStore

func SetStore(store Store) ServiceOptionFunc

SetStore sets the persistence store for the namespace.Service.

func WithDefaults

func WithDefaults() ServiceOptionFunc

WithDefaults enables the namespace.Store to be initialize with default namespaces

type Store

type Store interface {

	// Set persists the NameSpace object.
	//
	// When the object already exists it is overwritten.
	Set(ns *domain.NameSpace) error

	// Delete removes the NameSpace from the store.
	//
	// Delete matches by the Prefix of the Namespace.
	Delete(ns *domain.NameSpace) error

	// Len returns the number of stored namespaces
	Len() int

	// GetWithPrefix returns the NameSpace for a given prefix.
	// When the prefix is not found, an ErrNameSpaceNotFound error is returned.
	GetWithPrefix(prefix string) (ns *domain.NameSpace, err error)

	// GetWithBase returns the NameSpace for a given base-URI.
	// When the base-URI is not found, an ErrNameSpaceNotFound error is returned.
	GetWithBase(base string) (ns *domain.NameSpace, err error)

	// List returns a list of all the NameSpaces
	List() ([]*domain.NameSpace, error)
}

Store provides functionality to query and persist namespaces.

Jump to

Keyboard shortcuts

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