restclient

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrServiceNotAvailable = errors.New("service not available")

Functions

This section is empty.

Types

type RequestData

type RequestData interface {
	any
}

type ResponseBody

type ResponseBody interface {
	any
}

type ResponseData

type ResponseData[Body any] interface {
	Status() int
	Body() *Body
	Header() http.Header
	Error() error
}

ResponseData interface to encapsulate response data with Status, Body, Header and Error

func Delete

func Delete[T ResponseBody](ctx context.Context, client *RestClient, path string, headers map[string]string) ResponseData[T]

Delete call delete request

func DeleteWithErrorData

func DeleteWithErrorData[T ResponseBody, E ResponseErrorData](ctx context.Context, client *RestClient, path string, headers map[string]string) (ResponseData[T], *E)

DeleteWithErrorData call delete request and when error occurs decode err into ResponseErrorData

func Get

func Get[T ResponseBody](ctx context.Context, client *RestClient, path string, headers map[string]string) ResponseData[T]

Get call get request

func GetWithErrorData

func GetWithErrorData[T ResponseBody, E ResponseErrorData](ctx context.Context, client *RestClient, path string, headers map[string]string) (ResponseData[T], *E)

GetWithErrorData call get request and when error occurs decode err into ResponseErrorData

func Patch

func Patch[T ResponseBody, R RequestData](ctx context.Context, client *RestClient, path string, entityBody *R, headers map[string]string) ResponseData[T]

Patch call patch request

func PatchWithErrorData

func PatchWithErrorData[T ResponseBody, E ResponseErrorData, R RequestData](ctx context.Context, client *RestClient, path string, entityBody *R, headers map[string]string) (ResponseData[T], *E)

PatchWithErrorData call patch request and when error occurs decode err into ResponseErrorData

func Post

func Post[T ResponseBody, R RequestData](ctx context.Context, client *RestClient, path string, entityBody *R, headers map[string]string) ResponseData[T]

Post call post request

func PostBodyString

func PostBodyString[T ResponseBody](ctx context.Context, client *RestClient, path string, bodyString string, headers map[string]string) ResponseData[T]

PostBodyString call post request with string as body to set Content-type pass is header map

Ex.: to make a form url encoded request
	`PostBodyString[MyReturnData](ctx, client, "/my-path", "body string for urlencoded...", map[string]string{"Content-Type": "application/x-www-form-urlencoded"})

func PostWithErrorData

func PostWithErrorData[T ResponseBody, E ResponseErrorData, R RequestData](ctx context.Context, client *RestClient, path string, entityBody *R, headers map[string]string) (ResponseData[T], *E)

PostWithErrorData call post request and when error occurs decode err into ResponseErrorData

func Put

func Put[T ResponseBody, R RequestData](ctx context.Context, client *RestClient, path string, entityBody *R, headers map[string]string) ResponseData[T]

Put call put request

func PutWithErrorData

func PutWithErrorData[T ResponseBody, E ResponseErrorData, R RequestData](ctx context.Context, client *RestClient, path string, entityBody *R, headers map[string]string) (ResponseData[T], *E)

PutWithErrorData call put request and when error occurs decode err into ResponseErrorData

type ResponseErrorData

type ResponseErrorData interface {
	any
}

type RestClient

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

RestClient client http to encapsulate rest calls

func NewRestClient

func NewRestClient(name string, baseURL string, timeout uint) *RestClient

NewRestClient create new client http with timeout configuration and New Relic transport configuration

Jump to

Keyboard shortcuts

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