namespace

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: Unlicense Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrEmpty the namespaced key is empty.
	ErrEmpty = errors.Const("namespace: namespaced key is empty")
	// ErrNil the namespace or key is nil.
	// This is returned by methods on the zero value of [NS] or [NSK]
	ErrNil = errors.Const("namespace: nil namespace or key")
	// ErrTooLong the namespaced key exceeded the max allowed length.
	ErrTooLong = errors.Const("namespace: namespaced key is too long")
	// ErrInvalidChar the namespaced key contained an invalid character
	ErrInvalidChar = errors.Const("namespace: namespaced key contains illegal characters")
	// ErrTrailingSep the nsk contained a trailing `:`
	ErrTrailingSep = errors.Const("namespace: namespace contains trailing ':' character")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type NS

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

NS is a namespace. A namespace can only contain digits, lowercase letters, underscores and hyphens.

To compare namespaces use `==` operator directly (not on the pointer value) or use the NS.Equal method.

var Default NS = Namespace("minecraft")

Default this is the namespace used for minecraft items/effects ect. Plugins should use their own namespace if they aren't overriding vanilla features

func Namespace

func Namespace(namespace string) NS

Namespace creates a new namespace from the given string.

This panics if the length of the namespace is larger than [MaxLength] or is zero. All invalid characters in the namespace are replaced with underscores.

func ParseNamespace

func ParseNamespace(v string, strict bool) (NS, error)

ParseNamespace creates a new namespace from the given string.

This returns an error if the length of the namespace is larger than [MaxLength] or is zero. If strict mode is enabled, this returns an error when it encounters an invalid character. Otherwise, this replaces all invalid characters with underscores.

func (NS) Equal

func (n NS) Equal(n2 NS) bool

Equal returns if this namespace and the given namespace are equal.

func (NS) IsNil

func (n NS) IsNil() bool

IsNil returns if this nsk is nil. if this returns true, calling NS.Key will panic.

func (NS) Key

func (n NS) Key(k string) NSK

Key creates a new key inside this namespace. All invalid characters in the will be replaced with an underscore.

This panics if the length of the key is larger than [MaxLength] or is zero. If NS.IsNil returns true, this will panic.

func (*NS) MarshalText

func (n *NS) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler

func (NS) ParseKey

func (n NS) ParseKey(k string) (nsk NSK, err error)

ParseKey creates a new key inside this namespace. Unlike NS.Key, this will return an error if any invalid characters are encountered.

This returns an error if the length of the key is larger than [MaxLength] or is zero If NS.IsNil returns true, this will return ErrNil.

func (NS) String

func (n NS) String() string

func (*NS) UnmarshalText

func (n *NS) UnmarshalText(text []byte) (err error)

UnmarshalText implements encoding.TextUnmarshaler

type NSK

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

NSK is a namespaced key. A namespace can only contain digits, lowercase letters, underscores, hyphens, forward slash and dots.

To compare namespaces use `==` operator directly (not on the pointer value) or use the NSK.Equal method.

func Key

func Key(namespacedKey string) NSK

Key creates a new namespaced key from the given string.

This panics if the length of the key is larger than [MaxLength] or is zero. All invalid characters in the namespaced key are replaced with underscores.

func ParseKey

func ParseKey(namespacedKey string, strict bool) (NSK, error)

ParseKey creates a new namespaced key from the given string.

This returns an error if the length of the key is larger than [MaxLength] or is zero. If strict mode is enabled, this returns an error when it encounters an invalid character. Otherwise, this replaces all invalid characters with underscores.

func (NSK) Equal

func (n NSK) Equal(n2 NSK) bool

Equal returns if this namespaced key is equal to the given namespaced key.

func (NSK) IsNil

func (n NSK) IsNil() bool

IsNil returns if this nsk is nil. if this returns true, calling NSK.Namespace will panic.

func (NSK) Key

func (n NSK) Key() string

Key gets the key part of the namespaced key (the part after the ':'). If the namespaced key is nil, this returns an empty string.

func (*NSK) MarshalText

func (n *NSK) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler

func (NSK) Namespace

func (n NSK) Namespace() NS

Namespace gets the namespace for this key. If NSK.IsNil returns true, this will panic.

func (NSK) String

func (n NSK) String() string

func (*NSK) UnmarshalText

func (n *NSK) UnmarshalText(text []byte) (err error)

UnmarshalText implements encoding.TextUnmarshaler

Jump to

Keyboard shortcuts

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