goCall

package module
v0.0.0-...-4498e05 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: MIT Imports: 7 Imported by: 0

README

goCall

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddArguments

func AddArguments(endpoint string, arguments map[string]string) (string, error)

AddArguments Adds url arguments to a string with special notation

func AddQuery

func AddQuery(endpoint string, query map[string]string) string

AddQuery Adds query parameters to url

Types

type API

type API struct {
	BaseURL         string
	Endpoints       map[string]*Endpoint
	DefaultHandlers *CallbackRouter
	Client          *Client
}

func NewAPI

func NewAPI(baseURL string) *API

func (*API) AddEndpoint

func (a *API) AddEndpoint(name string, endpoint *Endpoint)

func (*API) Call

func (a *API) Call(name string, params, query map[string]string) error

type AuthToken

type AuthToken struct {
	Token  string
	Prefix string
}

func NewAuthToken

func NewAuthToken(token, prefix string) *AuthToken

type Authentication

type Authentication interface {
	// contains filtered or unexported methods
}

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

func NewBasicAuth

func NewBasicAuth(username, password string) *BasicAuth

type CallbackRouter

type CallbackRouter struct {
	Handlers       map[int]HandlerFunc
	DefaultHandler HandlerFunc
}

func NewCallbackRouter

func NewCallbackRouter() *CallbackRouter

func (*CallbackRouter) Handle

func (c *CallbackRouter) Handle(r *http.Response, content interface{}) error

Handle handles a response for an specific status code

func (*CallbackRouter) RegisterHandler

func (c *CallbackRouter) RegisterHandler(status int, f HandlerFunc)

RegisterHandler registers a new handler

type Client

type Client struct {
	Client         *http.Client
	Authentication Authentication
}

func NewClient

func NewClient(auth Authentication) *Client

NewClient creates a new client

func (*Client) Do

func (c *Client) Do(BaseURL string, endpoint *Endpoint, params, query map[string]string) error

Do Processes the request

func (*Client) SetAuth

func (c *Client) SetAuth(auth Authentication)

SetAuth sets authentication info

type Endpoint

type Endpoint struct {
	Path    string
	Method  string
	Handler *CallbackRouter
}

func NewEndpoint

func NewEndpoint(path string, method string, callback *CallbackRouter) *Endpoint

NewEndpoint Creates a new endpoint with given arguments

func (*Endpoint) RenderEndpoint

func (e *Endpoint) RenderEndpoint(arguments, query map[string]string) (string, error)

RenderEndpoint Renders given endpoint with query parameters and url parameters

type HandlerFunc

type HandlerFunc func(r *http.Response, c interface{}) error

Jump to

Keyboard shortcuts

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