client

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MediaTypePlain = "text/plain"
	MediaTypeXml   = "application/xml"

	MediaTypeJson = "application/json"
	MediaTypeForm = "application/x-www-form-urlencoded"
)

Variables

This section is empty.

Functions

func AddOptions

func AddOptions(s string, opt interface{}) (string, error)

func EncodeJson

func EncodeJson(v interface{}) (*bytes.Buffer, error)

func EncodeURL

func EncodeURL(body interface{}) (*strings.Reader, error)

Types

type Client

type Client struct {

	// Base URL for API requests. BaseURL should always be specified with a trailing slash.
	BaseURL *url.URL

	// User agent used when communicating with the Artifactory API.
	UserAgent string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(baseURL string, httpClient *http.Client) (*Client, error)

NewClient creates a Client from a provided base url for an artifactory instance and a service Client

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*http.Response, error)

Do executes a give request with the given context. If the parameter v is a writer the body will be written to it in raw format, else v is assumed to be a struct to unmarshal the body into assuming JSON format. If v is nil then the body is not read and can be manually parsed from the response

func (*Client) NewJSONEncodedRequest

func (c *Client) NewJSONEncodedRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewJSONEncodedRequest is a wrapper around Client.NewRequest which encodes the body as a JSON object

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body io.Reader) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is included as the request body.

func (*Client) NewURLEncodedRequest

func (c *Client) NewURLEncodedRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewURLEncodedRequest is a wrapper around Client.NewRequest which encodes the body with URL encoding

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response `json:"-"`                // HTTP response that caused this error
	Errors   []Status       `json:"errors,omitempty"` // Individual errors
}

ErrorResponse reports one or more errors caused by an API request.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Service

type Service struct {
	Client *Client
}

type Status

type Status struct {
	Status  int    `json:"status"`  // Validation error status code
	Message string `json:"message"` // Message describing the error. Errors with Code == "custom" will always have this set.
}

Status is the individual error provided by the API

func (*Status) Error

func (e *Status) Error() string

Jump to

Keyboard shortcuts

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