perseshttp

package
v0.53.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 9 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}
	ConflictError        = &RequestError{Message: "document already exists", StatusCode: http.StatusConflict}
)

Functions

This section is empty.

Types

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 {
	// Default headers for all client requests (not editable)
	Headers map[string]string
	// base is the root URL for all invocations of the client
	BaseURL *common.URL
	// Set specific behavior of the client. If not, set http.DefaultClient will be used.
	Client *http.Client
}

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

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) 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")

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 *common.URL, headers map[string]string) *Request

NewRequest creates a new request helper object for accessing resource on 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 any) *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 any) error

Object stores the result into respObj.

Jump to

Keyboard shortcuts

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