Documentation
¶
Overview ¶
Package service builds the typed API client a command needs, the same way for every Norcube service: it resolves the profile, the target organization, the service endpoint, a token source for the service's audience (from the selected credential store) and the shared HTTP transport. Product command packages call New once per invocation instead of each wiring these by hand.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoOrganization = clierr.Usage(errors.New("no active organization. Run `norcube org use <slug>` or pass --org <slug>"))
ErrNoOrganization is returned when nothing names the organization to act in.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client[T any] struct { // API is the generated client. API T // Service is the registry entry the client talks to. Service registry.Service // Config is the resolved configuration of the selected profile. Config *config.Config // Flags are the invocation's global flags. Flags *clictx.Flags // Org is the organization the client acts in. Org api.Organization // Tokens mints the access tokens the client sends. Tokens *auth.TokenSource // Output is the requested output format. Output string }
Client is a typed API client plus the context it was built in.
func New ¶
func New[T any](cmd *cobra.Command, key string, ctor Constructor[T], opts ...Option) (*Client[T], error)
New returns a client for the registry service key (config.ServiceSnapDB, ...), built with ctor.
func (*Client[T]) OrgLabel ¶
OrgLabel names the target organization for messages: its slug when known, otherwise its id.
func (*Client[T]) Streaming ¶ added in v0.19.0
func (c *Client[T]) Streaming(ctor Constructor[T]) (T, error)
Streaming returns the same API client built on the streaming transport: no limit on the total response time (a server-sent event stream or a large export may take as long as it needs), but a body that stops sending data for the idle timeout fails. Use it only for those endpoints; regular requests keep the per-request timeout of API.
type Constructor ¶
Constructor creates a generated client for a base URL that sends its requests through httpc and edit.
type Option ¶
type Option func(*options)
Option adjusts how New picks the organization.
func ForOrg ¶
ForOrg makes the client act in this organization, skipping --org and the profile (for commands that pick the organization themselves).
func WithOrgDefault ¶
func WithOrgDefault(fn func() (api.Organization, bool)) Option
WithOrgDefault supplies an organization that applies when neither --org nor NORCUBE_ORG is given, ahead of the profile's (a project file such as .langsync.json).