gitlab

package
v14.48.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package gitlab provides an HTTP client for the GitLab internal API. It is the replacement for the client and gitlabnet packages and is being introduced incrementally as part of the consolidation described in https://gitlab.com/gitlab-org/gitlab-shell/-/issues/834.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseJSON

func ParseJSON(resp *http.Response, dst any) error

ParseJSON decodes a successful (< 400) HTTP response body into dst, or returns a *client.APIError describing the failure. The error semantics deliberately match those of the old client package so that sub-clients migrated to this package do not need to change their error handling:

  • 4xx/5xx with a JSON {"message":"…"} body → *client.APIError{Msg: message}
  • 4xx/5xx with no decodable message → *client.APIError{Msg: "Internal API error (N)"}
  • 2xx with non-JSON body → errors.New("parsing failed")

Types

type Client

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

Client is an HTTP client for the GitLab internal API.

func New

func New(cfg *Config) (*Client, error)

New creates a new Client from the given Config.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) (*http.Response, error)

Get makes a GET request to the given internal API path.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body any) (*http.Response, error)

Post makes a POST request to the given internal API path with a JSON body.

type Config

type Config struct {
	// GitlabURL is the base URL of the GitLab instance.
	GitlabURL string
	// RelativeURLRoot is an optional relative URL root prefix (for Unix socket URLs).
	RelativeURLRoot string
	// User is the HTTP basic auth username.
	User string
	// Password is the HTTP basic auth password.
	Password string
	// Secret is the HS256 JWT signing secret. Must not be empty.
	Secret string
	// CaFile is the path to a custom CA certificate file.
	CaFile string
	// CaPath is the path to a directory of custom CA certificate files.
	CaPath string
	// ReadTimeoutSeconds is the HTTP read timeout. Defaults to 300s when zero.
	ReadTimeoutSeconds uint64
}

Config holds the configuration for the GitLab internal API client.

Jump to

Keyboard shortcuts

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