Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultErrorHandler(resp *http.Response) error
- func DefaultErrorHandlerWithReason(resp *http.Response) error
- func IsBadRequest(err error) bool
- func IsForbidden(err error) bool
- func IsNotFound(err error) bool
- func IsUnauthorized(err error) bool
- type Client
- type ClientError
- func (*ClientError) Descriptor() ([]byte, []int)deprecated
- func (x *ClientError) Error() string
- func (x *ClientError) GetPath() string
- func (x *ClientError) GetReason() string
- func (x *ClientError) GetStatusCode() int32
- func (*ClientError) ProtoMessage()
- func (x *ClientError) ProtoReflect() protoreflect.Message
- func (x *ClientError) Reset()
- func (x *ClientError) String() string
- type ClientInterface
- type ClientOption
- func WithFeatureFlagCheckCounter(counter otelmetric.Int64Counter) ClientOption
- func WithMeterProvider(meterProvider otelmetric.MeterProvider) ClientOption
- func WithRateLimiter(limiter httpz.Limiter) ClientOption
- func WithRetryConfig(retryConfig RetryConfig) ClientOption
- func WithTLSConfig(tlsConfig *tls.Config) ClientOption
- func WithTextMapPropagator(p propagation.TextMapPropagator) ClientOption
- func WithTracerProvider(traceProvider trace.TracerProvider) ClientOption
- func WithUserAgent(userAgent string) ClientOption
- func WithValidator(v protovalidate.Validator) ClientOption
- type DefaultApiError
- type DoOption
- func WithAgentToken(agentToken api.AgentToken) DoOption
- func WithAgentTokenAndType(agentTokenAndType api.AgentTokenWithType) DoOption
- func WithAgentType(agentType api.AgentType) DoOption
- func WithFeatureFlags(s *featureflag.Set) DoOption
- func WithHeader(header http.Header) DoOption
- func WithJSONRequestBody(body any) DoOption
- func WithJWT(withJWT bool) DoOption
- func WithJobToken(jobToken string) DoOption
- func WithMethod(method string) DoOption
- func WithPath(path string) DoOption
- func WithProtoJSONRequestBody(body proto.Message) DoOption
- func WithQuery(query url.Values) DoOption
- func WithRequestBodyBytes(body []byte, contentType string) DoOption
- func WithResponseHandler(handler ResponseHandler) DoOption
- func WithoutRetries() DoOption
- type ErrHandler
- type HTTPClient
- type ResponseHandler
- func MultiResponseHandler(handlers ...ResponseHandler) ResponseHandler
- func NakedResponseHandler(response **http.Response) ResponseHandler
- func NoContentResponseHandler() ResponseHandler
- func ProtoJSONResponseHandler(response proto.Message) ResponseHandler
- func ProtoJSONResponseHandlerWithErr(response proto.Message, errHandler ErrHandler) ResponseHandler
- func ProtoJSONResponseHandlerWithStructuredErrReason(response proto.Message) ResponseHandler
- func RawBodyResponseHandler(expectedStatusCodes []int, expectedContentType string, body *mem.BufferSlice) ResponseHandler
- type ResponseHandlerStruct
- type RetryConfig
Constants ¶
const ( AgentTokenHeader = "Gitlab-Agent-Api-Request" //nolint: gosec AgentTypeHeader = "Gitlab-Agent-Type" //nolint: gosec )
Variables ¶
var File_internal_gitlab_gitlab_proto protoreflect.FileDescriptor
Functions ¶
func DefaultErrorHandler ¶
func DefaultErrorHandlerWithReason ¶
DefaultErrorHandlerWithReason tries to add an error reason from the response body. If no reason can be found, none is added to the response
func IsBadRequest ¶
func IsForbidden ¶
func IsNotFound ¶
func IsUnauthorized ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) FeatureFlagCheckCounter ¶ added in v18.3.0
func (c *Client) FeatureFlagCheckCounter() otelmetric.Int64Counter
type ClientError ¶
type ClientError struct {
StatusCode int32 `protobuf:"varint,1,opt,name=status_code,json=statusCode,proto3" json:"status_code,omitempty"`
Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"`
Reason string `protobuf:"bytes,3,opt,name=reason,proto3" json:"reason,omitempty"`
// contains filtered or unexported fields
}
func DefaultErrorHandlerTyped ¶ added in v18.6.0
func DefaultErrorHandlerTyped(resp *http.Response) *ClientError
func (*ClientError) Descriptor
deprecated
func (*ClientError) Descriptor() ([]byte, []int)
Deprecated: Use ClientError.ProtoReflect.Descriptor instead.
func (*ClientError) Error ¶
func (x *ClientError) Error() string
func (*ClientError) GetPath ¶
func (x *ClientError) GetPath() string
func (*ClientError) GetReason ¶
func (x *ClientError) GetReason() string
func (*ClientError) GetStatusCode ¶
func (x *ClientError) GetStatusCode() int32
func (*ClientError) ProtoMessage ¶
func (*ClientError) ProtoMessage()
func (*ClientError) ProtoReflect ¶
func (x *ClientError) ProtoReflect() protoreflect.Message
func (*ClientError) Reset ¶
func (x *ClientError) Reset()
func (*ClientError) String ¶
func (x *ClientError) String() string
type ClientInterface ¶
type ClientOption ¶
type ClientOption func(*clientConfig)
ClientOption to configure the client.
func WithFeatureFlagCheckCounter ¶ added in v18.3.0
func WithFeatureFlagCheckCounter(counter otelmetric.Int64Counter) ClientOption
func WithMeterProvider ¶
func WithMeterProvider(meterProvider otelmetric.MeterProvider) ClientOption
WithMeterProvider sets a custom meter provider to be used, otherwise the OTEL's global MeterProvider is used.
func WithRateLimiter ¶
func WithRateLimiter(limiter httpz.Limiter) ClientOption
WithRateLimiter sets the rate limiter to use.
func WithRetryConfig ¶
func WithRetryConfig(retryConfig RetryConfig) ClientOption
WithRetryConfig configures retry behavior.
func WithTLSConfig ¶
func WithTLSConfig(tlsConfig *tls.Config) ClientOption
WithTLSConfig sets the TLS config to use.
func WithTextMapPropagator ¶
func WithTextMapPropagator(p propagation.TextMapPropagator) ClientOption
WithTextMapPropagator sets a custom trace propagator to be used, otherwise the OTEL's global TextMapPropagator is used.
func WithTracerProvider ¶
func WithTracerProvider(traceProvider trace.TracerProvider) ClientOption
WithTracerProvider sets a custom trace provider to be used, otherwise the OTEL's global TracerProvider is used.
func WithUserAgent ¶
func WithUserAgent(userAgent string) ClientOption
WithUserAgent configures the User-Agent header on the http client.
func WithValidator ¶
func WithValidator(v protovalidate.Validator) ClientOption
WithValidator sets the proto validator to use.
type DefaultApiError ¶
type DefaultApiError struct {
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
// contains filtered or unexported fields
}
func (*DefaultApiError) Descriptor
deprecated
func (*DefaultApiError) Descriptor() ([]byte, []int)
Deprecated: Use DefaultApiError.ProtoReflect.Descriptor instead.
func (*DefaultApiError) GetMessage ¶
func (x *DefaultApiError) GetMessage() string
func (*DefaultApiError) ProtoMessage ¶
func (*DefaultApiError) ProtoMessage()
func (*DefaultApiError) ProtoReflect ¶
func (x *DefaultApiError) ProtoReflect() protoreflect.Message
func (*DefaultApiError) Reset ¶
func (x *DefaultApiError) Reset()
func (*DefaultApiError) String ¶
func (x *DefaultApiError) String() string
type DoOption ¶
type DoOption func(*doConfig) error
DoOption to configure the Do call of the client.
func WithAgentToken ¶
func WithAgentToken(agentToken api.AgentToken) DoOption
func WithAgentTokenAndType ¶ added in v18.2.0
func WithAgentTokenAndType(agentTokenAndType api.AgentTokenWithType) DoOption
func WithAgentType ¶ added in v18.2.0
func WithFeatureFlags ¶ added in v18.3.0
func WithFeatureFlags(s *featureflag.Set) DoOption
func WithHeader ¶
func WithJSONRequestBody ¶
WithJSONRequestBody specifies the object to marshal to JSON and use as request body. Do NOT use this method with proto messages, use WithProtoJSONRequestBody instead.
func WithJobToken ¶
WithJobToken sets the CI job token to authenticate this API request. See https://docs.gitlab.com/ee/api/rest/#job-tokens.
func WithMethod ¶
func WithProtoJSONRequestBody ¶
WithProtoJSONRequestBody specifies the object to marshal to JSON and use as request body. Use this method with proto messages.
func WithRequestBodyBytes ¶
WithRequestBodyBytes sets the request body and HTTP Content-Type header if contentType is not empty.
func WithResponseHandler ¶
func WithResponseHandler(handler ResponseHandler) DoOption
func WithoutRetries ¶
func WithoutRetries() DoOption
type ErrHandler ¶
type HTTPClient ¶
type HTTPClient interface {
Do(*retryablehttp.Request) (*http.Response, error)
}
type ResponseHandler ¶
type ResponseHandler interface {
// Handle is invoked with HTTP client's response and error values.
Handle(protovalidate.Validator, *http.Response, error) error
// Accept returns the value to send in the Accept HTTP header.
// Empty string means no value should be sent.
Accept() string
}
func MultiResponseHandler ¶ added in v18.7.0
func MultiResponseHandler(handlers ...ResponseHandler) ResponseHandler
MultiResponseHandler joins multiple response handlers. First non-empty accept header is used.
func NakedResponseHandler ¶
func NakedResponseHandler(response **http.Response) ResponseHandler
func NoContentResponseHandler ¶
func NoContentResponseHandler() ResponseHandler
NoContentResponseHandler can be used when no response is expected or response must be discarded.
func ProtoJSONResponseHandler ¶
func ProtoJSONResponseHandler(response proto.Message) ResponseHandler
func ProtoJSONResponseHandlerWithErr ¶
func ProtoJSONResponseHandlerWithErr(response proto.Message, errHandler ErrHandler) ResponseHandler
func ProtoJSONResponseHandlerWithStructuredErrReason ¶
func ProtoJSONResponseHandlerWithStructuredErrReason(response proto.Message) ResponseHandler
func RawBodyResponseHandler ¶ added in v18.6.0
func RawBodyResponseHandler(expectedStatusCodes []int, expectedContentType string, body *mem.BufferSlice) ResponseHandler
RawBodyResponseHandler allows the caller to get the raw response as a memory buffer. The caller is responsible for freeing the buffer when it's no longer needed. This response handler does not validate the response. Make sure it is valid before using it.
type ResponseHandlerStruct ¶
type ResponseHandlerStruct struct {
AcceptHeader string
HandleFunc func(protovalidate.Validator, *http.Response, error) error
}
func (ResponseHandlerStruct) Accept ¶
func (r ResponseHandlerStruct) Accept() string
func (ResponseHandlerStruct) Handle ¶
func (r ResponseHandlerStruct) Handle(v protovalidate.Validator, resp *http.Response, err error) error
type RetryConfig ¶
type RetryConfig struct {
// Logger instance. Can be either retryablehttp.Logger or retryablehttp.LeveledLogger
Logger any
RetryWaitMin time.Duration // Minimum time to wait
RetryWaitMax time.Duration // Maximum time to wait
RetryMax int // Maximum number of retries
// RequestLogHook allows a user-supplied function to be called
// before each retry.
RequestLogHook retryablehttp.RequestLogHook
// ResponseLogHook allows a user-supplied function to be called
// with the response from each HTTP request executed.
ResponseLogHook retryablehttp.ResponseLogHook
// CheckRetry specifies the policy for handling retries, and is called
// after each request. The default policy is retryablehttp.DefaultRetryPolicy.
CheckRetry retryablehttp.CheckRetry
// Backoff specifies the policy for how long to wait between retries.
// retryablehttp.DefaultBackoff is used by default.
Backoff retryablehttp.Backoff
}