command

package
v0.0.0-...-eda937b Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: Apache-2.0, MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDisallowsTrailingSlash = errors.New("a command must not include a trailing slash")

ErrDisallowsTrailingSlash is returned when parsing a string that ends with a trailing slash character.

View Source
var ErrRequiresLeadingSlash = errors.New("a command requires a leading slash character")

ErrRequiresLeadingSlash is returned when a parsing a string that doesn't start with a leading slash character.

View Source
var ErrRequiresLowercase = errors.New("UCAN path segments must must not contain upper-case characters")

ErrRequiresLowercase is returned if a Command contains, or would contain, uppercase unicode characters.

View Source
var Undef = Command{}

Undef is the zero value of Command, representing an undefined command. Using Command{} directly is also acceptable.

Functions

This section is empty.

Types

type Command

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

Command is a concrete message (a "verb") that MUST be unambiguously interpretable by the Subject of a UCAN.

A Command is composed of a leading slash which is optionally followed by one or more slash-separated Segments of lowercase characters.

The underlying field is unexported so a Command can only be obtained from a validating constructor (New, Parse, MustParse or Top). This makes invalid Commands unrepresentable: a value of this type is always either the undefined zero value or a well-formed command.

Note: this is a struct rather than `type Command string` for two reasons — it prevents arbitrary strings being converted into a Command, and cbor-gen only recognises MarshalCBOR/UnmarshalCBOR on non-string (struct) types.

func MustParse

func MustParse(s string) Command

MustParse is like Parse but panics if s is not a valid Command. It is intended for package-level command definitions from constant strings.

func New

func New(segments ...string) Command

New creates a command from the provided segments. Segments are assumed to be well-formed; New does not validate them. To validate untrusted input, use Parse.

func Parse

func Parse(s string) (Command, error)

Parse verifies that the provided string contains the required segment structure and, if valid, returns the resulting Command.

func Top

func Top() Command

Top is the most powerful capability.

This function returns a Command that is a wildcard and therefore represents the most powerful ability. As such, it should be handled with care and used sparingly.

func (Command) Defined

func (c Command) Defined() bool

Defined reports whether the Command holds a value (i.e. is not the undefined zero value).

func (Command) Join

func (c Command) Join(segments ...string) Command

Join appends segments to the end of this command using the required segment separator.

func (Command) MarshalCBOR

func (c Command) MarshalCBOR(w io.Writer) error

func (Command) MarshalDagJSON

func (c Command) MarshalDagJSON(w io.Writer) error

func (Command) MarshalJSON

func (c Command) MarshalJSON() ([]byte, error)

func (Command) Proves

func (c Command) Proves(other Command) bool

Proves returns true if the command is identical or a parent of the given other command.

For example, /crypto MAY be used to prove /crypto/sign but MUST NOT prove /stack/pop or /cryptocurrency.

https://github.com/ucan-wg/spec/blob/main/README.md#segment-structure

func (Command) Segments

func (c Command) Segments() []string

Segments returns the ordered segments that comprise the Command as a slice of strings.

func (Command) String

func (c Command) String() string

String returns the composed representation the command. This is also the required wire representation (before IPLD encoding occurs).

func (*Command) UnmarshalCBOR

func (c *Command) UnmarshalCBOR(r io.Reader) error

func (*Command) UnmarshalDagJSON

func (c *Command) UnmarshalDagJSON(r io.Reader) error

func (*Command) UnmarshalJSON

func (c *Command) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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