Documentation
¶
Index ¶
- Variables
- type Command
- func (c Command) Defined() bool
- func (c Command) Join(segments ...string) Command
- func (c Command) MarshalCBOR(w io.Writer) error
- func (c Command) MarshalDagJSON(w io.Writer) error
- func (c Command) MarshalJSON() ([]byte, error)
- func (c Command) Proves(other Command) bool
- func (c Command) Segments() []string
- func (c Command) String() string
- func (c *Command) UnmarshalCBOR(r io.Reader) error
- func (c *Command) UnmarshalDagJSON(r io.Reader) error
- func (c *Command) UnmarshalJSON(b []byte) error
Constants ¶
This section is empty.
Variables ¶
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.
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.
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.
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 ¶
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 ¶
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 ¶
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 ¶
Defined reports whether the Command holds a value (i.e. is not the undefined zero value).
func (Command) Join ¶
Join appends segments to the end of this command using the required segment separator.
func (Command) MarshalJSON ¶
func (Command) Proves ¶
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 ¶
Segments returns the ordered segments that comprise the Command as a slice of strings.
func (Command) String ¶
String returns the composed representation the command. This is also the required wire representation (before IPLD encoding occurs).