Documentation
¶
Overview ¶
Package instance normalizes the GitLab base URL (gitlab.com, or the loopback test instance), checks URLs against it, reads the instance's version and edition, and turns GitLab web URLs into tool arguments.
The base URL is normalized once, so every request and every origin check compares the same scheme, host, port and sub-path (§4.9).
Index ¶
- Variables
- func IsLoopback(hostname string) bool
- type Instance
- func (i Instance) APIRoot() *url.URL
- func (i Instance) Host() string
- func (i Instance) Hostname() string
- func (i Instance) IsZero() bool
- func (i Instance) Path() string
- func (i Instance) ResolveURL(raw string) (Ref, error)
- func (i Instance) SameOrigin(u *url.URL) bool
- func (i Instance) Scheme() string
- func (i Instance) String() string
- func (i Instance) UnderAPIRoot(u *url.URL) bool
- func (i Instance) WebBase() *url.URL
- type Kind
- type Metadata
- type Ref
- type RefPath
- type Version
Constants ¶
This section is empty.
Variables ¶
var ErrInvalid = errors.New("invalid instance or URL")
ErrInvalid is wrapped by every error this package returns. The caller maps it to the [invalid] class.
var GitLabCom = Instance{/* contains filtered or unexported fields */}
GitLabCom is the one instance this server serves.
Functions ¶
func IsLoopback ¶
IsLoopback reports whether hostname is localhost or a loopback address (127.0.0.0/8 or ::1). Brackets and a trailing dot are tolerated.
Types ¶
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance is a normalized GitLab base URL: scheme, host[:port] and an optional sub-path such as "/gitlab".
func Parse ¶
Parse normalizes a base URL. A missing scheme is read as https. http is refused for a host that is not loopback, because the token would travel in the clear.
func (Instance) Host ¶
Host is host[:port] as it appears in a URL authority, with an IPv6 address bracketed and the default port left out.
func (Instance) ResolveURL ¶
ResolveURL turns a GitLab web URL on this instance into tool arguments. A URL on another host is refused, naming the configured instance (§6.1).
func (Instance) SameOrigin ¶
SameOrigin reports whether u has the instance's scheme, host and port. Host case and default ports are normalized.
func (Instance) UnderAPIRoot ¶
UnderAPIRoot reports whether u may carry the token: same origin, no credentials, and a path at or below the API root with no dot segments, raw or percent-encoded. It guards following a Link header (§11).
type Metadata ¶
Metadata is what the server keeps from /api/v4/metadata.
func NewMetadata ¶
NewMetadata parses the version metadata reports.
type Ref ¶
type Ref struct {
Kind Kind
Project string // full path, decoded: "example-group/sub/project"
IID int64 // issue, merge_request
ID int64 // pipeline, job
SHA string // commit
// Ref is the branch, tag or SHA of a file, a tree or a commit
// listing. See RefPathCandidates for refs with slashes.
Ref string
Path string // file path, or directory for a tree
Line int // from #L10
EndLine int // from #L10-20; 0 for a single line
From string // compare
To string // compare
Slug string // wiki page, may contain slashes
Note int64 // from #note_123 on an issue or merge request
// contains filtered or unexported fields
}
Ref is a web URL turned into tool arguments. Only the fields its Kind uses are set.
func (Ref) RefPathCandidates ¶
RefPathCandidates lists every split of a blob, raw, tree or commits URL's ref and path, shortest ref first, so a caller can check them against the project's branches and tags with one lookup. It is nil for other kinds.
type RefPath ¶
type RefPath struct{ Ref, Path string }
RefPath is one way to split a URL's ref-and-path.
type Version ¶
type Version struct {
Major, Minor, Patch int
// Suffix follows the dash, without it: "pre", "ee", "rc1".
Suffix string
// Raw is the text as given, trimmed.
Raw string
}
Version is a GitLab version as /api/v4/metadata reports it, such as "17.3.1-ee" or "19.5.0-pre".
func ParseVersion ¶
ParseVersion reads "major.minor[.patch][-suffix]". A leading "v" is tolerated and a missing patch reads as 0.