gofleetresources

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 13 Imported by: ? 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.

README

gofleetresources

Every fleet service prints a resource in one shape, whatever its kind: a slate record or worklog, a fleet run, an inbox row, a GitHub pull request. This module gives a Go reader that shape as types, the constants for each condition and shared identifier, and one parser for a resource's name.

JSON Schemas in the fleet library, terminal-library-fleet, define all of it. The module holds a byte copy of each one in the table below, and generates its constants from those copies:

File Holds
resource-shape-schema.json The envelope: kind, name, metadata, spec, and status with its conditions
resource-condition-types-schema.json Each condition type, its normal status, the kinds that carry it, and its reasons in order
identifiers-shared-across-stores-schema.json Each identity that more than one store joins on, with its OpenTelemetry attribute and warehouse column
service-resource-collections-schema.json Each collection of resources that a service serves by name: its pattern, name template, route and contract

Install

go get github.com/datapointchris/gofleetresources

It needs the Go version that its go.mod declares, or newer. It imports nothing outside the standard library.

Names take the form <service>/<collection>/<id>, except where a vendor's collection declares its own

The id is one path segment. Each byte outside [A-Za-z0-9._~-] is percent-encoded, as RFC 3986 encodes a segment, so an inbox row keyed hard-to-read-sentences/fleet-audit is named fleet/inbox-rows/hard-to-read-sentences%2Ffleet-audit. GitHub's pull requests keep github/<owner>/<repo>/pulls/<n>.

collections := gofleetresources.DeclaredCollections()

name, err := gofleetresources.ParseName("fleet/inbox-rows/hard-to-read-sentences%2Ffleet-audit", collections)
if err != nil {
 return err // a *NameError
}
name.Service()          // "fleet"
name.Collection().Key   // "fleet-inbox-rows"
name.ID()               // "hard-to-read-sentences/fleet-audit", decoded

rows, _ := collections.Lookup("fleet-inbox-rows")
built, err := rows.Name(map[string]string{"id": "hard-to-read-sentences/fleet-audit"})
built.String()          // "fleet/inbox-rows/hard-to-read-sentences%2Ffleet-audit"

ParseName matches the name against each collection's pattern, and reads its segments by the collection's x-name-template. When no pattern matches, ParseName refuses the name with a *NameError. Its message names the grammar, and each collection of the service that the name starts with:

slate/record/4048 is not a resource name. A name is <service>/<collection>/<id>, with the id
percent-encoded as one path segment. Its collections are slate/records/{id}, such as
slate/records/4048; slate/worklogs/{id}, such as slate/worklogs/4941.2.

Name.APIPath expands the collection's x-api-path with the name's segments, such as /api/v1/runs/99764/ for fleet/runs/99764. It returns false for a collection with no route of its own. ParseCollections reads another copy of the collections schema, such as a test's.

A resource decodes into Resource, and its spec into the kind's own type

var resource gofleetresources.Resource
if err := json.Unmarshal(body, &resource); err != nil {
 return err
}
var spec issueSpec
if err := json.Unmarshal(resource.Spec, &spec); err != nil {
 return err
}
for _, condition := range resource.Status.Conditions {
 definition, _ := gofleetresources.LookupConditionType(condition.Type)
 unusual := condition.Status != definition.Normal // a view colors this one
}
id, _ := resource.Metadata.Identifiers[gofleetresources.IdentifierSlateRecord].Int()

Status.Extra keeps each key that a kind adds to status beside state, conditions and children, so a reader that writes a resource back loses none of them.

A service validates what it serves against the shape. SchemaCopies embeds the copies, and ResourceShapeSchemaFile names the shape's.

To read a route's answer as a resource, a client names MediaType in Accept. MediaType is application/vnd.fleet.resource+json. The service then answers with that Content-Type. Without it, the route answers in its own shape.

Each copy changes in the library first, then is copied here again

A copy is never edited here. Each copy stays byte-equal to its library file, under that file's $id. Where the fleet data catalog lists this repo as a producer, its catalog-contracts copied-values check fails a copy whose bytes differ. So a schema change lands in the library first. Then copy the changed file here byte for byte, and generate the constants again:

cp ~/.local/share/terminal-library-fleet/<file>-schema.json .
go generate ./...   # rewrites schema_constants_generated.go
go test ./...       # fails while the generated file and the copies disagree

Releases

A push to main runs the tests on each operating system in the release workflow's matrix. Then it tags the next version from the conventional-commit types. The module stays on 0.x until its API is settled.

Documentation

Overview

Package gofleetresources holds the one shape in which every fleet service prints a resource: its conditions, the identifiers that other stores join on, and the parser for a resource's name.

The types follow JSON Schemas that the fleet library, terminal-library-fleet, owns. The module embeds a byte copy of each in SchemaCopies. The constants for each condition status, condition type, reason and identifier are generated from those copies.

A reader parses a name against the collections that the collections schema declares:

collections := gofleetresources.DeclaredCollections()
name, err := gofleetresources.ParseName("github/datapointchris/slate/pulls/412", collections)
if err != nil {
	return err // a *NameError, naming the grammar and an example of each nearby collection
}
name.Service()         // "github"
name.ID()              // "412"
name.Segment("repo")   // "slate", true
name.APIPath()         // "/repos/datapointchris/slate/pulls/412", true

Index

Constants

View Source
const (
	ResourceShapeSchemaFile                 = "resource-shape-schema.json"
	ResourceConditionTypesSchemaFile        = "resource-condition-types-schema.json"
	IdentifiersSharedAcrossStoresSchemaFile = "identifiers-shared-across-stores-schema.json"
	ServiceResourceCollectionsSchemaFile    = "service-resource-collections-schema.json"
)

The file names of the schema copies that SchemaCopies holds. Each is a byte copy of the file of the same name in the fleet library, terminal-library-fleet, and keeps that file's $id.

View Source
const MediaType = "application/vnd.fleet.resource+json"

MediaType is what a client names in Accept to have a service answer with a resource, and the Content-Type of that answer. A request that names another media type gets the route's own shape, so a client that never asks keeps reading what it always read.

View Source
const NameGrammar = "<service>/<collection>/<id>, with the id percent-encoded as one path segment"

NameGrammar is the form of every resource name, apart from a vendor's collection, which declares its own pattern.

View Source
const SchemaVersion = 1

SchemaVersion is the version of resource-shape-schema.json that a Resource prints in.

Variables

View Source
var SchemaCopies embed.FS

SchemaCopies holds the module's schema copies, by the file names above. A service's test validates a resource it serves against the shape copy here, and DeclaredCollections reads the collections copy.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	// Key is the collection's $defs key, such as slate-records.
	Key         string
	Description string
	// Service is the service that serves the collection, such as slate or github.
	Service string
	// Kinds names the resource kinds that the collection holds.
	Kinds []string
	// Pattern is the regular expression that every name in the collection matches.
	Pattern string
	// NameTemplate names each segment of the collection's names, as an RFC 6570 template such as
	// github/{owner}/{repo}/pulls/{id}.
	NameTemplate string
	// APIPath is the route at which the service serves one resource, such as
	// /api/v1/records/{id}. It is empty where the service serves no route of its own for one.
	APIPath string
	// Contract is the catalog contract that each resource in the collection holds to.
	Contract string
	// Identifier is the identifier that the collection's id is.
	Identifier Identifier
	Examples   []string
	// contains filtered or unexported fields
}

Collection is one collection of resources that a service serves by name, as one $defs entry of service-resource-collections-schema.json declares it.

func (Collection) Name

func (c Collection) Name(values map[string]string) (Name, error)

Name builds the name of the resource in the collection whose template variables take values, such as {"id": "4048"}, percent-encoding each value as one segment. It refuses values that leave a variable empty or name one that the template lacks. It also refuses a name that fails the collection's pattern.

type Collections

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

Collections is the set of collections that one copy of service-resource-collections-schema.json declares. ParseCollections and DeclaredCollections build it.

func DeclaredCollections

func DeclaredCollections() Collections

DeclaredCollections returns the collections in the module's copy of service-resource-collections-schema.json. The module's tests read that copy, so a release whose copy does not parse is never cut, and DeclaredCollections panics only where one was.

func ParseCollections

func ParseCollections(schema []byte) (Collections, error)

ParseCollections reads every collection that schema declares, in the order of its oneOf. schema is a copy of service-resource-collections-schema.json. It refuses a collection that lacks a pattern, a service or a name template, and one whose examples do not each parse by its own pattern and template alone.

func (Collections) All

func (c Collections) All() []Collection

All returns every collection, in the order of the schema's oneOf.

func (Collections) Lookup

func (c Collections) Lookup(key string) (Collection, bool)

Lookup returns the collection whose $defs key is key, and false where none is.

type Condition

type Condition struct {
	Type   ConditionType   `json:"type"`
	Status ConditionStatus `json:"status"`
	Reason ConditionReason `json:"reason"`
	// Message is the reason's detail for a person, such as the records a dependency waits on.
	Message string `json:"message,omitempty"`
}

Condition is one condition that a service derives on every read, as resource-shape-schema.json gives a condition. resource-condition-types-schema.json lists each type and its reasons, and ConditionTypeDefinitions reads that list.

type ConditionReason

type ConditionReason string

ConditionReason is why a condition's status is what it is, one of the reasons its type lists.

const (
	// ReadyReasonClosed: The issue is completed or canceled.
	ReadyReasonClosed ConditionReason = "Closed"
	// ReadyReasonIncoming: The issue is still in triage.
	ReadyReasonIncoming ConditionReason = "Incoming"
	// ReadyReasonInitiativeShelved: Its initiative is someday.
	ReadyReasonInitiativeShelved ConditionReason = "InitiativeShelved"
	// ReadyReasonDependencyOpen: An issue it depends on is open.
	ReadyReasonDependencyOpen ConditionReason = "DependencyOpen"
	// ReadyReasonInitiativeWaits: Its initiative waits on an open record.
	ReadyReasonInitiativeWaits ConditionReason = "InitiativeWaits"
	// ReadyReasonChildrenOpen: A child issue is open.
	ReadyReasonChildrenOpen ConditionReason = "ChildrenOpen"
	// ReadyReasonDeferred: Its deferred-until date is ahead.
	ReadyReasonDeferred ConditionReason = "Deferred"
	// ReadyReasonClaimed: A live claim holds it.
	ReadyReasonClaimed ConditionReason = "Claimed"
	// ReadyReasonNothingBlocks: None of the reasons above holds, so the issue can start.
	ReadyReasonNothingBlocks ConditionReason = "NothingBlocks"
)

The reasons that the Ready condition type lists, in its order.

const (
	// HeldReasonLiveClaim: A live claim holds the record, and the message names its holder.
	HeldReasonLiveClaim ConditionReason = "LiveClaim"
	// HeldReasonNoClaim: No live claim holds the record.
	HeldReasonNoClaim ConditionReason = "NoClaim"
)

The reasons that the Held condition type lists, in its order.

const (
	// StillHoldsReasonHolds: The latest check found that the record still describes work to do.
	StillHoldsReasonHolds ConditionReason = "Holds"
	// StillHoldsReasonCorrected: The latest check found that the record describes work to do once what
	// was wrong in it is rewritten.
	StillHoldsReasonCorrected ConditionReason = "Corrected"
	// StillHoldsReasonDone: The latest check found the work already done.
	StillHoldsReasonDone ConditionReason = "Done"
	// StillHoldsReasonGone: The latest check found that what the record describes no longer exists.
	StillHoldsReasonGone ConditionReason = "Gone"
	// StillHoldsReasonDuplicate: The latest check found another record carrying the same work.
	StillHoldsReasonDuplicate ConditionReason = "Duplicate"
	// StillHoldsReasonContradicts: The latest check found that something else rules out what the record
	// asks for.
	StillHoldsReasonContradicts ConditionReason = "Contradicts"
	// StillHoldsReasonUnclear: The latest check settled nothing, so the record comes due again at its
	// interval.
	StillHoldsReasonUnclear ConditionReason = "Unclear"
)

The reasons that the StillHolds condition type lists, in its order.

const (
	// NeedsPersonReasonClaimWaitsOnPerson: The claim holding the record waits on a person, and the
	// message says on what.
	NeedsPersonReasonClaimWaitsOnPerson ConditionReason = "ClaimWaitsOnPerson"
	// NeedsPersonReasonSessionWaitsOnPerson: The run's session waits on a person, and the message says
	// since when.
	NeedsPersonReasonSessionWaitsOnPerson ConditionReason = "SessionWaitsOnPerson"
	// NeedsPersonReasonRowWaitsOnPerson: The inbox row moves only once a person acts, and the message
	// says what it waits on, such as an answer or a review.
	NeedsPersonReasonRowWaitsOnPerson ConditionReason = "RowWaitsOnPerson"
	// NeedsPersonReasonNothingAsked: Nothing on the resource waits on a person.
	NeedsPersonReasonNothingAsked ConditionReason = "NothingAsked"
)

The reasons that the NeedsPerson condition type lists, in its order.

const (
	// AdmittedReasonStarted: Admission started the run's newest attempt, and the message says when.
	AdmittedReasonStarted ConditionReason = "Started"
	// AdmittedReasonEndedUnadmitted: The run ended before any admission started it: a person canceled
	// it, or its dispatch stopped taking work.
	AdmittedReasonEndedUnadmitted ConditionReason = "EndedUnadmitted"
	// AdmittedReasonNotBefore: The run waits for the time its schedule booked it at.
	AdmittedReasonNotBefore ConditionReason = "NotBefore"
	// AdmittedReasonQuietBackOff: The run waits out its job's back-off after runs that ended quietly.
	AdmittedReasonQuietBackOff ConditionReason = "QuietBackOff"
	// AdmittedReasonAfter: The run waits on runs it declared it goes after.
	AdmittedReasonAfter ConditionReason = "After"
	// AdmittedReasonPaused: A pause holds runs of its kind.
	AdmittedReasonPaused ConditionReason = "Paused"
	// AdmittedReasonTrackedRecord: The tracker does not yet read the record the run is for as ready.
	AdmittedReasonTrackedRecord ConditionReason = "TrackedRecord"
	// AdmittedReasonRegistry: The repo registry does not yet hold what the run needs.
	AdmittedReasonRegistry ConditionReason = "Registry"
	// AdmittedReasonRepoFindings: Open finding rows on the run's repo hold it.
	AdmittedReasonRepoFindings ConditionReason = "RepoFindings"
	// AdmittedReasonRoleAccount: No account its place starts the run under is free.
	AdmittedReasonRoleAccount ConditionReason = "RoleAccount"
	// AdmittedReasonClaudeProfile: The Claude Code profile the run pulls is not yet resolved.
	AdmittedReasonClaudeProfile ConditionReason = "ClaudeProfile"
	// AdmittedReasonCaptureScreen: The capture screenshot the run reads has not yet reached the
	// warehouse.
	AdmittedReasonCaptureScreen ConditionReason = "CaptureScreen"
	// AdmittedReasonBudget: The model budget leaves no room for the run.
	AdmittedReasonBudget ConditionReason = "Budget"
	// AdmittedReasonKind: Its kind already runs as many runs at once as its limit allows.
	AdmittedReasonKind ConditionReason = "Kind"
	// AdmittedReasonDispatch: Its dispatch already runs as many runs at once as its limit allows.
	AdmittedReasonDispatch ConditionReason = "Dispatch"
	// AdmittedReasonRoom: No place has room for the run.
	AdmittedReasonRoom ConditionReason = "Room"
	// AdmittedReasonLease: Another run holds a lease the run needs.
	AdmittedReasonLease ConditionReason = "Lease"
	// AdmittedReasonAwaitsNextPass: No gate holds the queued run, so the next admission pass may start
	// it.
	AdmittedReasonAwaitsNextPass ConditionReason = "AwaitsNextPass"
)

The reasons that the Admitted condition type lists, in its order.

type ConditionReasonDefinition

type ConditionReasonDefinition struct {
	Reason      ConditionReason
	Description string
}

ConditionReasonDefinition is one reason that a condition type lists.

type ConditionStatus

type ConditionStatus string

ConditionStatus is whether a condition holds, as Kubernetes spells a condition's status.

const (
	ConditionTrue    ConditionStatus = "True"
	ConditionFalse   ConditionStatus = "False"
	ConditionUnknown ConditionStatus = "Unknown"
)

Each status that a condition takes, as resource-shape-schema.json gives a condition.

type ConditionType

type ConditionType string

ConditionType is what a condition reports, such as Ready.

const (
	// ConditionTypeReady: Whether the issue can start now, as slate's readiness decides. Its reasons
	// are an order, and the first that holds is the condition's reason.
	ConditionTypeReady ConditionType = "Ready"
	// ConditionTypeHeld: Whether a live claim holds the record, so no other session takes it.
	ConditionTypeHeld ConditionType = "Held"
	// ConditionTypeStillHolds: Whether the record still describes the world, as its latest check found.
	// Its reasons are slate's check verdicts, one each, in PascalCase. A record that no check has read
	// carries no StillHolds condition.
	ConditionTypeStillHolds ConditionType = "StillHolds"
	// ConditionTypeNeedsPerson: Whether the work on the resource waits on a person.
	ConditionTypeNeedsPerson ConditionType = "NeedsPerson"
	// ConditionTypeAdmitted: Whether admission started the run's newest attempt. Its reasons are an
	// order, and the first that holds is the condition's reason. A queued run reads False with the gate
	// that admission last held it at, and the message gives admission's own words for the hold.
	ConditionTypeAdmitted ConditionType = "Admitted"
)

Each condition type that resource-condition-types-schema.json declares, in its order.

type ConditionTypeDefinition

type ConditionTypeDefinition struct {
	Type        ConditionType
	Description string
	// Normal is the status a view treats as unremarkable. A view colors a condition whose status
	// differs from it.
	Normal ConditionStatus
	// Kinds names the resource kinds that carry the condition.
	Kinds []string
	// Reasons lists the type's reasons in the schema's order. Where the type's description says
	// its reasons are an order, the first reason that holds is the condition's reason.
	Reasons []ConditionReasonDefinition
}

ConditionTypeDefinition is one condition type as resource-condition-types-schema.json declares it.

func ConditionTypeDefinitions

func ConditionTypeDefinitions() []ConditionTypeDefinition

ConditionTypeDefinitions returns every condition type that the module's copy of resource-condition-types-schema.json declares, in its order.

func LookupConditionType

func LookupConditionType(conditionType ConditionType) (ConditionTypeDefinition, bool)

LookupConditionType returns the definition of the condition type named conditionType, and false where the schema declares no such type.

type Identifier

type Identifier string

Identifier is the name of an identity that more than one store carries, such as slate-record or flow, as identifiers-shared-across-stores-schema.json names it.

const (
	// IdentifierActor: One principal acting through a fleet service, by the name its token carries: a
	// service's client id, such as slate-svc-fleet-runs, or a person's login.
	IdentifierActor Identifier = "actor"
	// IdentifierAgentKind: One kind of agent the fleet runs.
	IdentifierAgentKind Identifier = "agent-kind"
	// IdentifierAPIMessage: One response from the model.
	IdentifierAPIMessage Identifier = "api-message"
	// IdentifierClaudeCodeTaskRun: One background task Claude Code ran in a session, by the id its task
	// notification carries.
	IdentifierClaudeCodeTaskRun Identifier = "claude-code-task-run"
	// IdentifierClaudeSession: One Claude Code session.
	IdentifierClaudeSession Identifier = "claude-session"
	// IdentifierCommit: One git commit.
	IdentifierCommit Identifier = "commit"
	// IdentifierDotfilesRun: One run of a dotfiles verb, by the id its run record carries.
	IdentifierDotfilesRun Identifier = "dotfiles-run"
	// IdentifierFleetRun: One execution of a fleet job, by the id silver.runs gives it. A queued job
	// and its run are one row under one number, so a job waiting in the queue already carries its run's
	// id.
	IdentifierFleetRun Identifier = "fleet-run"
	// IdentifierFlow: One cause followed through the fleet.
	IdentifierFlow Identifier = "flow"
	// IdentifierGitHubActionsRun: One GitHub Actions workflow run, by the id GitHub gives it.
	IdentifierGitHubActionsRun Identifier = "github-actions-run"
	// IdentifierHomelabApplyRun: One plan, apply, container operation or backup trigger, by the id the
	// homelab apply worker's runs table gives it.
	IdentifierHomelabApplyRun Identifier = "homelab-apply-run"
	// IdentifierInboxRow: One row of the fleet's inbox.
	IdentifierInboxRow Identifier = "inbox-row"
	// IdentifierMachine: One box, by its lowercased short hostname.
	IdentifierMachine Identifier = "machine"
	// IdentifierMachineRun: One run of a fleet tool on a machine, as gold.machine_runs names it: its
	// source's prefix, then that source's own id.
	IdentifierMachineRun Identifier = "machine-run"
	// IdentifierPsycheEvalRun: One evaluation run psyche keeps in its eval_run table.
	IdentifierPsycheEvalRun Identifier = "psyche-eval-run"
	// IdentifierPullRequest: One pull request in a repo.
	IdentifierPullRequest Identifier = "pull-request"
	// IdentifierRepo: One registered repo, by its registry name.
	IdentifierRepo Identifier = "repo"
	// IdentifierScheduledJob: One job on the fleet's schedule.
	IdentifierScheduledJob Identifier = "scheduled-job"
	// IdentifierSlateRecord: One slate issue, initiative or idea, by its number.
	IdentifierSlateRecord Identifier = "slate-record"
	// IdentifierSlateWorklog: One worklog of a slate record, by its record's number and its place among
	// that record's worklogs, such as 4941.2.
	IdentifierSlateWorklog Identifier = "slate-worklog"
	// IdentifierToolUse: One tool call in a Claude Code session.
	IdentifierToolUse Identifier = "tool-use"
	// IdentifierTrace: One OpenTelemetry trace.
	IdentifierTrace Identifier = "trace"
	// IdentifierYplSyncRun: One sync of the YouTube library ypl keeps in its sync_runs table.
	IdentifierYplSyncRun Identifier = "ypl-sync-run"
)

Each identifier that identifiers-shared-across-stores-schema.json declares, sorted by name.

type IdentifierDefinition

type IdentifierDefinition struct {
	Identifier  Identifier
	Description string
	// ValueType is the JSON type of the identifier's value, string or integer.
	ValueType string
	// OTelAttribute is the attribute that an OpenTelemetry span, log or event carries the
	// identifier under. It is empty for a trace, which OpenTelemetry carries in its own trace id.
	OTelAttribute string
	// WarehouseColumn is the column that a warehouse table names the identifier.
	WarehouseColumn string
}

IdentifierDefinition is one identifier as identifiers-shared-across-stores-schema.json declares it.

func IdentifierDefinitions

func IdentifierDefinitions() []IdentifierDefinition

IdentifierDefinitions returns every identifier that the module's copy of identifiers-shared-across-stores-schema.json declares, sorted by name.

func LookupIdentifier

func LookupIdentifier(identifier Identifier) (IdentifierDefinition, bool)

LookupIdentifier returns the definition of identifier, and false where the schema declares no such identifier.

type IdentifierValue

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

IdentifierValue is one identifier's value, as the JSON wrote it: an integer for a JSON integer, and a string for a JSON string. It does not check the value against the type that identifiers-shared-across-stores-schema.json gives the identifier. IdentifierDefinition's ValueType holds that type.

func IntIdentifier

func IntIdentifier(number int64) IdentifierValue

IntIdentifier returns an identifier value holding number.

func StringIdentifier

func StringIdentifier(text string) IdentifierValue

StringIdentifier returns an identifier value holding text.

func (IdentifierValue) Int

func (v IdentifierValue) Int() (int64, bool)

Int returns the value's integer, and false where the value is a string.

func (IdentifierValue) MarshalJSON

func (v IdentifierValue) MarshalJSON() ([]byte, error)

MarshalJSON writes the value as a JSON integer or string.

func (IdentifierValue) String

func (v IdentifierValue) String() string

String returns the value as text: a string as it is, and an integer in decimal.

func (*IdentifierValue) UnmarshalJSON

func (v *IdentifierValue) UnmarshalJSON(data []byte) error

UnmarshalJSON reads a JSON string or integer, and refuses any other value.

type Metadata

type Metadata struct {
	// Created and Updated are written in UTC, whatever their location.
	Created time.Time `json:"created,omitzero"`
	Updated time.Time `json:"updated,omitzero"`
	// Owners names the resources this one belongs to, such as an issue's initiative.
	Owners    []string   `json:"owners,omitzero"`
	Relations []Relation `json:"relations,omitzero"`
	// Identifiers holds every identity that another store joins on, keyed by its name in
	// identifiers-shared-across-stores-schema.json. The shape requires the key, so Resource writes
	// a nil map as {}.
	Identifiers map[Identifier]IdentifierValue `json:"identifiers"`
}

Metadata is what every resource carries whatever its kind.

type Name

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

Name is a resource's name, parsed against the collection whose pattern it matched. ParseName and Collection.Name build one.

func ParseName

func ParseName(raw string, collections Collections) (Name, error)

ParseName reads raw as a resource's name, against the collections whose patterns it may match. It refuses a name that matches no collection's pattern, or more than one, with a *NameError.

func (Name) APIPath

func (n Name) APIPath() (string, bool)

APIPath returns the route at which the name's service serves the resource, with each placeholder taking the segment of the same name, encoded. It returns false where the collection declares no route.

func (Name) Collection

func (n Name) Collection() Collection

Collection returns the collection that holds the named resource.

func (Name) ID

func (n Name) ID() string

ID returns the name's id segment, decoded.

func (Name) Segment

func (n Name) Segment(variable string) (string, bool)

Segment returns the decoded value of the template variable called variable, such as owner in github/{owner}/{repo}/pulls/{id}, and false where the collection's template has no such variable.

func (Name) Service

func (n Name) Service() string

Service returns the service that serves the named resource, such as slate or github.

func (Name) String

func (n Name) String() string

String returns the name as it is written, each segment percent-encoded.

type NameError

type NameError struct {
	// Name is the string that was refused.
	Name string
	// Near holds the collections of the service that the name starts with, or every collection
	// where no service matches.
	Near []Collection
	// Matched holds each collection whose pattern matched, where more than one did.
	Matched []Collection
}

NameError says why a string is not a resource name. Its message names the grammar, and the collections near the name with an example of each.

func (*NameError) Error

func (e *NameError) Error() string

type Relation

type Relation struct {
	// Type says how the two relate, such as DiscoveredFrom.
	Type string `json:"type"`
	Name string `json:"name"`
}

Relation is one other resource that a resource points at, and how.

type Resource

type Resource struct {
	SchemaVersion int    `json:"schema_version"`
	Kind          string `json:"kind"`
	// Name is the resource's name, which ParseName reads.
	Name     string   `json:"name"`
	Metadata Metadata `json:"metadata"`
	// Spec is the kind's own object, as the service wrote it. A reader decodes it into the kind's
	// own type with json.Unmarshal. The shape requires an object, so an empty Spec is written as {}.
	Spec   json.RawMessage `json:"spec"`
	Status Status          `json:"status"`
}

Resource is one object that a fleet service serves, in the shape resource-shape-schema.json holds. Spec holds what the resource's author set, in its kind's own keys, and Status what its service derives or observes.

func (Resource) MarshalJSON

func (r Resource) MarshalJSON() ([]byte, error)

MarshalJSON writes the resource as the shape requires it: an empty Spec and nil identifiers as {}, and each time in UTC.

type Status

type Status struct {
	// State is the resource's lifecycle, in its service's own words, such as open or running.
	State      string      `json:"state,omitempty"`
	Conditions []Condition `json:"conditions,omitzero"`
	// Children names what the resource produced, such as a slate issue's pull requests.
	Children []string `json:"children,omitzero"`
	// Extra holds each key that the resource's kind adds beside the three above, as the service
	// wrote it. A key that names one of the three is ignored when the status is written.
	Extra map[string]json.RawMessage `json:"-"`
}

Status is what a resource's service derives or observes.

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

MarshalJSON writes the status's three keys and each key of Extra beside them.

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(data []byte) error

UnmarshalJSON reads the status's three keys, and keeps every other key in Extra.

Directories

Path Synopsis
internal
cmd/write-schema-constants command
Command write-schema-constants writes schema_constants_generated.go from the schema copies in the current directory.
Command write-schema-constants writes schema_constants_generated.go from the schema copies in the current directory.
schemaconstants
Package schemaconstants renders the Go file of constants that the module's schema copies declare: each condition status, condition type, reason and identifier, and the definitions that describe them.
Package schemaconstants renders the Go file of constants that the module's schema copies declare: each condition status, condition type, reason and identifier, and the definitions that describe them.

Jump to

Keyboard shortcuts

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