client

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2020 License: MIT Imports: 16 Imported by: 11

Documentation

Index

Constants

View Source
const (
	DefaultUserAgent      string = "go-rest-utility/v1"
	DefaultAcceptEncoding string = "gzip"
)

Variables

View Source
var (
	ErrUnauthorized = errors.New("unauthorized")
	ErrForbidden    = errors.New("forbidden")
	ErrNotFound     = errors.New("not found")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL       *url.URL
	TokenProvider auth.TokenProvider
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts ...Option) *Client

NewClient will create a new REST Client.

func (*Client) Do

func (c *Client) Do(ctx context.Context, r *Request) (*Response, error)

func (*Client) DoAndUnmarshal

func (c *Client) DoAndUnmarshal(ctx context.Context, r *Request, v interface{}) error

type Option

type Option func(*Client)

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithDatadogTracing added in v0.2.0

func WithDatadogTracing(serviceName string) Option

WithDatadogTracing will add a Datadog transport to the client so that it will automatically inject trace-headers.

Should be used when you trace your application with Datadog.

func WithOpenCensusTracing added in v0.2.0

func WithOpenCensusTracing() Option

WithDatadogTracing will add an OpenCensus transport to the client so that it will automatically inject trace-headers.

Should be used when you trace your application with OpenCensus.

func WithTokenProvider

func WithTokenProvider(provider auth.TokenProvider) Option

type Request

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

func Connect

func Connect(uriTemplate string) *Request

func Delete

func Delete(uriTemplate string) *Request

func Get

func Get(uriTemplate string) *Request
func Head(uriTemplate string) *Request

func NewRequest

func NewRequest(method, uriTemplate string) *Request

func Options

func Options(uriTemplate string) *Request

func Patch

func Patch(uriTemplate string) *Request

func Post

func Post(uriTemplate string) *Request

func Put

func Put(uriTemplate string) *Request

func Trace

func Trace(uriTemplate string) *Request

func (*Request) Assign

func (r *Request) Assign(variable string, value interface{}) *Request

func (*Request) ExpandURL

func (r *Request) ExpandURL(baseURL *url.URL) (*url.URL, error)

ExpandURL combines the baseURL with the expanded URI template to form the final URL to be used for this Request. If no baseURL is provided the returned URL is just the expanded URI template

func (*Request) SetHeader

func (r *Request) SetHeader(key, value string) *Request

func (*Request) WithJSONPayload

func (r *Request) WithJSONPayload(payload interface{}) *Request

type Response

type Response struct {
	http.Response
}

func (*Response) Unmarshal

func (r *Response) Unmarshal(v interface{}) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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