perseshttp

package
v0.37.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RequestInternalError = &RequestError{Message: "internal server error", StatusCode: http.StatusInternalServerError}
	RequestNotFoundError = &RequestError{Message: "document not found", StatusCode: http.StatusNotFound}
)

Functions

This section is empty.

Types

type BasicAuth

type BasicAuth struct {
	User     string `json:"user" yaml:"user"`
	Password string `json:"password" yaml:"password,omitempty"`
	// PasswordFile is a path to a file that contains a password
	PasswordFile string `json:"password_file,omitempty" yaml:"password_file,omitempty"`
}

func (*BasicAuth) Verify

func (b *BasicAuth) Verify() error

type QueryInterface

type QueryInterface interface {
	GetValues() url.Values
}

QueryInterface defines the query interface that you can set in the Request

type RESTClient

type RESTClient struct {

	// base is the root URL for all invocations of the client
	BaseURL *url.URL
	// Set specific behavior of the client.  If not set http.DefaultClient will be used.
	Client *http.Client
	// contains filtered or unexported fields
}

RESTClient defines an HTTP client designed for the HTTP request to a REST API.

func NewFromConfig

func NewFromConfig(config RestConfigClient) (*RESTClient, error)

NewFromConfig create an instance of RESTClient using the config passed as parameter

func (*RESTClient) Delete

func (c *RESTClient) Delete() *Request

Delete begins a Delete request. Short for c.newRequest("DELETE")

func (*RESTClient) Get

func (c *RESTClient) Get() *Request

Get begins a GET request. Short for c.newRequest("GET")

func (*RESTClient) GetHeaders

func (c *RESTClient) GetHeaders() map[string]string

GetHeaders gets the headers

func (*RESTClient) GetToken

func (c *RESTClient) GetToken() string

GetToken gets the token

func (*RESTClient) Patch

func (c *RESTClient) Patch() *Request

Patch begins a Patch request. Short for c.newRequest("PATCH")

func (*RESTClient) Post

func (c *RESTClient) Post() *Request

Post begins a Post request. Short for c.newRequest("POST")

func (*RESTClient) Put

func (c *RESTClient) Put() *Request

Put begins a Put request. Short for c.newRequest("PUT")

func (*RESTClient) SetToken

func (c *RESTClient) SetToken(token string)

SetToken set the token (thread safe)

type Request

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

Request allows for building up a request to a server in a chained fashion. Any errors are stored until the end of your call, so you only have to check once.

func NewRequest

func NewRequest(client *http.Client, method string, baseURL *url.URL, token string, basicAuth *BasicAuth, headers map[string]string) *Request

NewRequest creates a new request helper object for accessing resource on a the API

func (*Request) APIPrefix

func (r *Request) APIPrefix(apiPrefix string) *Request

APIPrefix set the api prefix to used (default /api)

func (*Request) APIVersion

func (r *Request) APIVersion(APIVersion string) *Request

APIVersion set the api version to used (default v1)

func (*Request) Body

func (r *Request) Body(obj interface{}) *Request

Body defines the body in the HTTP request. The body shall be json compatible

func (*Request) Do

func (r *Request) Do() *Response

Do build the query and execute it. The error and/or the response from the server are set in the object Response

func (*Request) Name

func (r *Request) Name(name string) *Request

Name set the name of the resource

func (*Request) Project

func (r *Request) Project(project string) *Request

Project set the project where the resource must be defined. It cannot be used at the same time with Request.Area

func (*Request) Query

func (r *Request) Query(query QueryInterface) *Request

Query set all queryParameter contains in the query passed as a parameter

func (*Request) Resource

func (r *Request) Resource(resource string) *Request

Resource set the resource that the client want to access (like project, prometheusRule ...etc.)

type RequestError

type RequestError struct {
	Message    string
	StatusCode int
	Err        error
}

RequestError is a format struct to defines the error the results of calling #Request.Do()

func (*RequestError) Error

func (re *RequestError) Error() string

func (*RequestError) Unwrap

func (re *RequestError) Unwrap() error

type Response

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

Response contains the result of calling #Request.Do()

func (*Response) Error

func (r *Response) Error() error

Error returns the error executing the request, nil if no error occurred.

func (*Response) Object

func (r *Response) Object(respObj interface{}) error

Object stores the result into respObj.

type RestConfigClient

type RestConfigClient struct {
	URL         string            `json:"url" yaml:"url"`
	InsecureTLS bool              `json:"insecure_tls,omitempty" yaml:"insecure_tls,omitempty"`
	Token       string            `json:"token,omitempty" yaml:"token,omitempty"`
	BasicAuth   *BasicAuth        `json:"basic_auth,omitempty" yaml:"basic_auth,omitempty"`
	Headers     map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
}

RestConfigClient defines all parameter that can be set to customize the RESTClient

Jump to

Keyboard shortcuts

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