Documentation ¶
Overview ¶
nolint:misspell // because namespaces often are not valid words
Package namespace provides support for managing namespaces for RDF or XML URIs.
Index ¶
- type Service
- func (s *Service) Delete(id string) error
- func (s *Service) Get(id string) (*domain.Namespace, error)
- func (s *Service) GetWithBase(baseURI string) (*domain.Namespace, error)
- func (s *Service) GetWithPrefix(prefix string) (*domain.Namespace, error)
- func (s *Service) Len() int
- func (s *Service) List() ([]*domain.Namespace, error)
- func (s *Service) Put(prefix, base string) (*domain.Namespace, error)
- func (s *Service) RegisterOtoService(server *otohttp.Server) error
- func (s *Service) SearchLabel(uri string) (string, error)
- func (s *Service) Set(ns *domain.Namespace) error
- type ServiceOptionFunc
- type Store
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) Get ¶ added in v0.2.1
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 (*Service) GetWithPrefix ¶ added in v0.2.1
func (*Service) List ¶
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
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 (*Service) SearchLabel ¶
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 ¶
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 ¶
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.