namespace

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

nolint:misspell // because namespaces often are not valid words

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) Delete

func (s *Service) Delete(id string) error

Delete removes a namespace from the store

func (*Service) Get added in v0.2.1

func (s *Service) Get(id string) (*domain.Namespace, error)

Get returns a Namespace by its identifier. When the it is not found it returns domain.ErrNameSpaceNotFound

func (*Service) GetWithBase added in v0.2.1

func (s *Service) GetWithBase(baseURI string) (*domain.Namespace, error)

func (*Service) GetWithPrefix added in v0.2.1

func (s *Service) GetWithPrefix(prefix string) (*domain.Namespace, error)

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) Put added in v0.2.1

func (s *Service) Put(prefix, base string) (*domain.Namespace, error)

Put 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) RegisterOtoService added in v0.2.1

func (s *Service) RegisterOtoService(server *otohttp.Server) error

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 {
	// Put persists the NameSpace object.
	//
	// When the object already exists it is overwritten.
	Put(ns *domain.Namespace) error

	// Delete removes the NameSpace from the store.
	//
	// Delete matches by the Prefix of the Namespace.
	Delete(ID string) error

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

	// Get returns a namespace by its ID
	Get(id string) (ns *domain.Namespace, err error)

	// 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