Documentation
¶
Index ¶
Constants ¶
const ( SchemeMemory = "memory" SchemeFile = "file" SchemeGit = "git" SchemeSSH = "ssh" SchemeHTTP = "http" SchemeHTTPs = "https" SchemaAlias = "keg" SchemeRegistry = "registry" SchemeS3 = "s3" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPOption ¶
type HTTPOption = func(t *Target)
func WithBasicAuth ¶
func WithBasicAuth(user, pass string) HTTPOption
func WithToken ¶
func WithToken(token string) HTTPOption
type Target ¶
type Target struct {
// File is the file to use when the Target is a file
File string `yaml:"file,omitempty"`
// Repo is the repo to use to resolve the User and Keg
Repo string `yaml:"repo,omitempty"`
// Url is the url for the target when represented as a scalar or explicit
// mapping value. Url is used when the target was http/s, git, ssh, etc
Url string `yaml:"url,omitempty"`
Memory bool
// Other options
User string `yaml:"user,omitempty"`
Keg string `yaml:"keg,omitempty"`
Password string `yaml:"password,omitempty"`
Token string `yaml:"token,omitempty"`
TokenEnv string `yaml:"tokenEnv,omitempty"`
// Readonly specifies in the target is readonly. Only api and file are
// writable
Readonly bool `yaml:"readonly,omitempty"`
}
Target describes a resolved KEG repository target.
Schema is the URI scheme when the target was written as a URL (for example "file", "http", "https"). Path is the URL path component or an absolute filesystem path when the target was supplied as a file path.
The Target type is the canonical, minimal shape used by tooling. Valid input forms that map into Target include:
- File targets:
- Scalar file paths such as "/abs/path", "./rel/path", "../rel/path", "~/path", or Windows drive paths.
- Mapping form with a "file" key. File values are cleaned with filepath.Clean; Expand will attempt to expand a leading tilde.
- API or HTTP targets:
- Full URL scalars (http:// or https://).
- Mapping form with "url" and optional user/password/token/tokenEnv. Query params like "readonly", "token", and "token-env" are honored.
- Registry API shorthand and structured form:
- Compact scalar shorthand "registry:user/keg" or "registry:/@user/keg".
- Mapping form with "repo", "user", and "keg" fields.
Fields:
- File: filesystem path for a local keg target.
- Repo: registry name when using an API style target.
- Url: canonical URL when provided or parsed from a scalar.
- User/Keg: structured registry pieces used to compose API paths.
- Password/Token/TokenEnv: credential hints. TokenEnv is preferred for production usage.
- Readonly: when true the target was requested read only.
func NewApi ¶
func NewApi(repo string, user, keg string, opts ...TargetOption) Target
NewApi constructs a Target representing a keg API endpoint.
func NewFile ¶
func NewFile(path string, opts ...TargetOption) Target
NewFile constructs a file target for a local filesystem path. The path is cleaned using filepath.Clean.
func NewMemory ¶
func NewMemory(kegalias string, opts ...TargetOption) Target
func Parse ¶
Parse parses a user-supplied target scalar into a Target.
Accepted input forms:
- File paths (absolute, ./, ../, ~, Windows drive). These produce File targets.
- Compact registry shorthand "registry:user/keg" or "registry:/@user/keg".
- HTTP/HTTPS URL scalars.
- Any URL-like scalar parsed by url.Parse.
The function is permissive with common variants (extra whitespace, duplicate slashes). It returns an error for empty or malformed shorthand inputs.
func (*Target) Expand ¶
Expand replaces environment variables and expands a leading tilde in File and Repo-related fields. It uses std.ExpandEnv and std.ExpandPath so behavior matches the rest of the code base.
Errors from ExpandPath are collected and returned as a joined error so callers can see expansion issues.
func (*Target) Host ¶
Host returns the hostname portion for HTTP/HTTPS targets. For file targets it returns an empty string.
func (*Target) Scheme ¶
Scheme reports the inferred scheme for this Target value. Repo implies the keg API scheme. File implies a local file scheme. Otherwise we fall back to detectScheme on the Url.
func (*Target) String ¶
String returns a human-friendly representation of the target. For registry API form it returns "repo:user/keg". For file it returns the file path. For HTTP targets it returns the canonical Url.
func (*Target) UnmarshalYAML ¶
UnmarshalYAML accepts either a scalar string (the URL or shorthand or file) or a mapping node that decodes into the full Target struct. Mapping form may include structured repo/user/keg or an explicit file field.
When a scalar is provided the value is parsed via Parse which recognizes file scalars, shorthand registry forms, and URL scalars.
type TargetOption ¶
type TargetOption = func(t *Target)
func WithReadonly ¶
func WithReadonly() TargetOption