unit

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package unit names a unit of work by its provider and the provider's key.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeysEqual added in v0.2.0

func KeysEqual(c Codec, a, b string) bool

KeysEqual says whether keys a and b of c's provider name the same thing.

func UseLabels added in v0.3.0

func UseLabels(r *Registry)

UseLabels makes r's codecs the ones Unit.Label asks. The composition root sets it once, before anything labels a unit.

func ValidProvider added in v0.2.0

func ValidProvider(id string) bool

ValidProvider says whether id has a provider id's shape: a lowercase letter, then up to 31 lowercase letters, digits, dashes or underscores.

Types

type Anchor

type Anchor struct {
	Unit      Unit      `json:"unit"`
	Ref       string    `json:"ref"` // slack "<conversation>/<ts>"; github "review:<id>", "comment:<id>", "commit:<oid>", "situation:<kind>"; "turn:<round>"; "row:<rev>"; "draft:<id>", "draft:<id>:<kind>" before v4
	Permalink string    `json:"permalink,omitempty"`
	At        time.Time `json:"at,omitzero"`
}

Anchor is a plugin's opaque reference to a message or event inside a unit.

func (Anchor) Valid

func (a Anchor) Valid() error

Valid says why a is not an anchor: Ref non-blank, one line, at most 300 bytes; Unit non-zero.

type Codec

type Codec interface {
	Provider() ProviderID
	Valid(key string) error
}

Codec validates the keys of one provider.

type Equaler added in v0.2.0

type Equaler interface {
	Equal(a, b string) bool
}

Equaler is an optional capability of a Codec: whether two keys of its provider name the same thing, such as logins compared without case. A codec without it compares keys byte for byte.

type KeyComparer added in v0.2.0

type KeyComparer interface {
	KeysEqual(p ProviderID, a, b string) bool
}

KeyComparer says whether two keys of provider p name the same thing.

type Labeler added in v0.3.0

type Labeler interface {
	Label(key string) string
}

Labeler is an optional capability of a Codec: how a person reads a key.

type Linker added in v0.2.0

type Linker interface {
	URL(key string) string
	KeyOf(url string) (key string, ok bool)
}

Linker is an optional capability of a Codec: the web address of a key, and the key an address names. A unit of a provider with addresses is named by its address wherever a person or an agent types it.

type Locator added in v0.2.0

type Locator interface {
	Locate(ctx context.Context, dir string) (u Unit, ok bool, err error)
}

Locator knows the unit a local checkout's directory holds, such as the pull request of its branch; ok is false when it holds none.

type OpaqueCodec

type OpaqueCodec struct{ ID ProviderID }

OpaqueCodec accepts any non-blank key without a line break.

func (OpaqueCodec) Provider

func (c OpaqueCodec) Provider() ProviderID

func (OpaqueCodec) Valid

func (c OpaqueCodec) Valid(key string) error

type ProviderID

type ProviderID string
const (
	GitHub    ProviderID = "github"
	Session   ProviderID = "session"
	Workspace ProviderID = "workspace"
	// Task is the provider the core keeps for tasks: the key is the
	// task's id.
	Task ProviderID = "task"
)

type Registry

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

func NewRegistry

func NewRegistry(cs ...Codec) *Registry

func (*Registry) Codec added in v0.2.0

func (r *Registry) Codec(p ProviderID) (Codec, bool)

Codec is p's codec.

func (*Registry) KeysEqual added in v0.2.0

func (r *Registry) KeysEqual(p ProviderID, a, b string) bool

KeysEqual says whether keys a and b of p name the same thing through p's codec; a provider r does not know compares byte for byte.

func (*Registry) Linked added in v0.2.0

func (r *Registry) Linked(p ProviderID) bool

Linked says whether p's units have web addresses.

func (*Registry) Parse

func (r *Registry) Parse(provider, key string) (Unit, error)

func (*Registry) ParseKey added in v0.7.0

func (r *Registry) ParseKey(raw string) (Unit, bool)

ParseKey is the unit a key names as a person types it, among the providers with addresses: the one whose codec takes raw as a key that its own address reads back. False when no provider's codec does, or more than one.

func (*Registry) ParseURL added in v0.2.0

func (r *Registry) ParseURL(raw string) (Unit, bool)

ParseURL is the unit a web address names, among the providers with addresses.

func (*Registry) Providers

func (r *Registry) Providers() []ProviderID

func (*Registry) Same added in v0.2.0

func (r *Registry) Same(a, b Unit) bool

Same says whether a and b name the same unit.

func (*Registry) Target added in v0.2.0

func (r *Registry) Target(p ProviderID) string

Target is how a command line names a unit of p: its codec's Target, else <p:key>.

func (*Registry) Targets added in v0.2.0

func (r *Registry) Targets(ps ...ProviderID) string

Targets is how a command line names a unit of any of ps, or of any provider of r when ps is empty: their targets as one, such as <url|ref|permalink|slack:key>.

func (*Registry) URL added in v0.2.0

func (r *Registry) URL(u Unit) (string, bool)

URL is u's web address; ok is false for a provider without addresses.

type Resolver added in v0.2.0

type Resolver interface {
	Resolve(ctx context.Context, address string) (key string, ok bool, err error)
}

Resolver is a codec whose provider must look an address up to find its unit, such as a Slack message ref or permalink to its direct message segment or thread; ok is false for an address that is not one of the provider's.

type Targeter added in v0.2.0

type Targeter interface {
	Target() string
}

Targeter is an optional capability of a Codec: how a command line names one of its units, such as <url>.

type Unit

type Unit struct {
	Provider ProviderID `json:"provider"`
	Key      string     `json:"key"`
}

func ParseAddress added in v0.3.0

func ParseAddress(raw string) (Unit, bool)

ParseAddress is the unit a web address names, as the codecs of the registry UseLabels set read it; false for an address none of them has.

func (Unit) Address added in v0.3.0

func (u Unit) Address() string

Address names u as a person or an agent types it: as its web address when the codec of its provider in the registry UseLabels set has one, else as provider:key.

func (Unit) IsZero

func (u Unit) IsZero() bool

func (Unit) Label

func (u Unit) Label() string

Label names u as users read it: as the codec of its provider in the registry UseLabels set labels its key, else as provider:key.

func (Unit) Less

func (u Unit) Less(o Unit) bool

Less orders by provider, then key; the sort order of every unit list.

func (Unit) String

func (u Unit) String() string

Jump to

Keyboard shortcuts

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