client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package client is a generic REST client for BasicAuth / JWT services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL  string
	Password string
	Username string
	Logger   logger
	Debug    bool
	Token    string
	http.Client
}

Client is a connection to a REST service.

func New

func New(o *Options) *Client

New returns a new client.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, url string, resp interface{}) error

Delete sends a Delete request to the given URL.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string, resp interface{}) error

Get sends a Get request to the given URL.

func (*Client) Login

func (c *Client) Login(ctx context.Context) error

Login logs into the service. It is optional to call this method as any Request will automatically call Login if the Client is missing its Token. Call this when you want feedback right away on the acceptance of the Username/Password credentials.

func (*Client) Patch

func (c *Client) Patch(ctx context.Context, url string, body, resp interface{}) error

Patch sends a Patch request to the given URL.

func (*Client) Post

func (c *Client) Post(ctx context.Context, url string, body, resp interface{}) error

Post sends a Post request to the given URL.

func (*Client) Put

func (c *Client) Put(ctx context.Context, url string, body, resp interface{}) error

Put sends a Put request to the given URL.

func (*Client) Request

func (c *Client) Request(ctx context.Context, method, path string, in, out interface{}) error

Request sends a method request to the given URL. If the Client does not have a token the Login method is called first. If a 401 response is received it assumes the token has expired and will re-Login and retry the request.

func (*Client) URL

func (c *Client) URL(path string) string

URL returns the URL for the given path.

type Error

type Error struct {
	Code int
	Text string
}

Error is an error returned by the HTTP client.

func (Error) Error

func (e Error) Error() string

Error implements the error interface for h.

type LoginResponse

type LoginResponse struct {
	Token string `json:"token"`
}

LoginResponse is the response payload for /login.

type Options

type Options struct {
	Username string
	Password string
	Address  string
}

Options are the options for the client.

func NewOptions

func NewOptions(f flagSet, serviceName string, port int) *Options

NewOptions returns the Options after binding to the flagset.

Jump to

Keyboard shortcuts

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