Documentation
¶
Overview ¶
Package resourceref provides a universal resource-reference type and a data-driven engine for defining owned URI schemes.
The governing rule is simple: a resource reference is a URI. Prefer the resource owner's canonical URI when one exists — an AWS ARN, a SPIFFE ID, a GitHub URL — and mint an owned URI only when one does not. Owner-canonical URIs pass through this package untouched; there is no translation layer for external resources.
Two layers ¶
ResourceRef is the universal type: any RFC 3986 URI, canonicalized and comparable, usable as a graph node ID, a lineage edge, or a field in any JSON IR.
The scheme subpackage defines owned URI schemes as data (a Profile), not code: a SPIFFE-strict URI subset, an authority (namespace owner) registry, per-authority path shapes, resource-type registries, and version/alias suffix grammar. Namespace owners define their own profiles; this package supplies only the mechanism, not any specific scheme instance.
What this package deliberately does not do ¶
It does not resolve references to locations — identifier is not locator. It does not authorize, invoke, or execute anything against a reference. It does not define any specific scheme instance. Those concerns belong to resolvers, invocation contracts, and whatever adopts this module.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoScheme = errors.New("resourceref: missing URI scheme")
ErrNoScheme is returned by Parse when the input has no URI scheme. A ResourceRef must be an absolute URI reference — relative references are not resource references.
Functions ¶
This section is empty.
Types ¶
type ResourceRef ¶
type ResourceRef struct {
// contains filtered or unexported fields
}
A ResourceRef is a parsed, canonicalized resource reference.
Construct one with Parse or MustParse; the zero value is not a valid reference (its String method returns "").
func MustParse ¶
func MustParse(s string) ResourceRef
MustParse is like Parse but panics if s cannot be parsed. It is intended for tests and package-level initialization from known-good literals, not for parsing untrusted input.
func Parse ¶
func Parse(s string) (ResourceRef, error)
Parse parses s as an absolute URI reference (RFC 3986) and returns its canonical ResourceRef form.
Canonicalization is conservative and never semantically reinterprets a reference's components:
- the scheme, and the host of a hierarchical reference, are lowercased;
- percent-encoding is normalized per RFC 3986 §6.2.2.2 — an encoded octet is decoded only when it corresponds to an unreserved character (ALPHA / DIGIT / "-" / "." / "_" / "~"), and any encoding that remains has its hex digits uppercased;
- dot segments are removed from hierarchical paths per RFC 3986 §5.2.4;
- no scheme-specific default (e.g. treating :443 as implied by https) is ever stripped or assumed.
Owner-canonical external references — an AWS ARN, a SPIFFE ID, a URN — pass through with their opaque or authority structure intact.
func (ResourceRef) Equal ¶
func (r ResourceRef) Equal(o ResourceRef) bool
Equal reports whether r and o refer to the same canonical reference.
func (ResourceRef) IsZero ¶
func (r ResourceRef) IsZero() bool
IsZero reports whether r is the zero ResourceRef.
func (ResourceRef) MarshalText ¶
func (r ResourceRef) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler, encoding the reference as its canonical string form. json.Marshal uses this automatically for any struct field of type ResourceRef, so it encodes as a plain JSON string.
Marshaling the zero value is an error: a ResourceRef field is either a real reference or should be represented as *ResourceRef (nil, with omitempty) — never as a silent empty string.
func (ResourceRef) Scheme ¶
func (r ResourceRef) Scheme() string
Scheme returns the reference's URI scheme, already lowercased by Parse.
func (ResourceRef) String ¶
func (r ResourceRef) String() string
String returns the reference's canonical form, or "" for the zero value.
func (*ResourceRef) UnmarshalText ¶
func (r *ResourceRef) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler by parsing text with Parse.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package schema embeds the JSON Schemas generated from this module's Go-first source of truth (see the gen/ directory), for external tooling (schemakit, documentation generators, non-Go consumers) and for other JSON Schema documents that want to $ref a resource-reference field or a scheme profile document.
|
Package schema embeds the JSON Schemas generated from this module's Go-first source of truth (see the gen/ directory), for external tooling (schemakit, documentation generators, non-Go consumers) and for other JSON Schema documents that want to $ref a resource-reference field or a scheme profile document. |
|
Package scheme defines owned URI schemes as data.
|
Package scheme defines owned URI schemes as data. |