rest

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTP_ENDPOINT = "HTTP_ENDPOINT"
	FORCE_TRACE   = "FORCE_TRACE"

	ApiAgent = "txsvc/rest"

	// format error messages
	MsgStatus = "%s. status: %d"
)

Variables

View Source
var (
	// ErrApiInvocationError indicates an error in an API call
	ErrApiInvocationError = errors.New("api invocation error")
)

Functions

func Duration

func Duration(d time.Duration, dicimal int) time.Duration

func NewLoggingTransport

func NewLoggingTransport(transport http.RoundTripper) *http.Client

func XID

func XID() string

Types

type ClientOption

type ClientOption interface {
	Apply(ds *settings.DialSettings)
}

func WithCredentials

func WithCredentials(clientid, secret string) ClientOption

WithCredentials returns a ClientOption that overrides the default credentials used for a service.

func WithEndpoint

func WithEndpoint(url string) ClientOption

WithEndpoint returns a ClientOption that overrides the default endpoint to be used for a service.

func WithToken

func WithToken(clientid, token string) ClientOption

WithCredentials returns a ClientOption that overrides the default token used for a service.

type LoggingTransport

type LoggingTransport struct {
	InnerTransport http.RoundTripper
}

RestClient - API client encapsulating the http client

func (*LoggingTransport) RoundTrip

func (t *LoggingTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip logs the request and reply if the log level is debug or trace

type RestClient

type RestClient struct {
	HttpClient *http.Client
	Settings   *settings.DialSettings
	Trace      string
}

RestClient - API client encapsulating the http client

func NewRestClient

func NewRestClient(ctx context.Context, opts ...ClientOption) (*RestClient, error)

func (*RestClient) DELETE

func (c *RestClient) DELETE(uri string, request, response interface{}) (int, error)

func (*RestClient) GET

func (c *RestClient) GET(uri string, response interface{}) (int, error)

GET is used to request data from the API. No payload, only queries!

func (*RestClient) POST

func (c *RestClient) POST(uri string, request, response interface{}) (int, error)

func (*RestClient) PUT

func (c *RestClient) PUT(uri string, request, response interface{}) (int, error)

func (*RestClient) SetClient

func (c *RestClient) SetClient(cl *http.Client)

Jump to

Keyboard shortcuts

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