api

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GET http method
	GET = "GET"

	// POST http method
	POST = "POST"

	// PUT http method
	PUT = "PUT"

	// PATCH http method
	PATCH = "PATCH"

	// DELETE http method
	DELETE = "DELETE"

	// HEAD http method
	HEAD = "HEAD"

	// OPTIONS http method
	OPTIONS = "OPTIONS"
)

Variables

This section is empty.

Functions

func AddResponseHandlers

func AddResponseHandlers(handlers ...ResponseHandlerFunc)

AddResponseHandlers : adds some response handlers to the current response handlers.

func Initialize

func Initialize(host, version string, port int, timeout, retryCount int, debug bool)

Initialize : initializes the client to the internal API.

Types

type Cache

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

Cache : cached results of some API calls.

func NewCache

func NewCache() (c *Cache)

NewCache : returns a new 'Cache' struct.

func (*Cache) Get

func (c *Cache) Get(key, locale string) (CachedValue, bool)

Get : gets a cached value.

func (*Cache) Save

func (c *Cache) Save(key, locale string, value interface{}, result Result, ok bool)

Save : saves the value to the cache.

type CachedValue

type CachedValue struct {
	Value  interface{}
	Result Result
	Ok     bool
}

CachedValue : cached result of a API call.

type Client

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

Client : client of an API.

var (
	// Main : main API client of the application.
	Main *Client

	// MainCache : main cache for the results of some API calls.
	MainCache = NewCache()
)

func NewClient

func NewClient(host, APIVersion string, port, timeout, retryCount int, debug bool) (client *Client)

NewClient : returns a new API client struct.

func (*Client) AddResponseHandlers

func (client *Client) AddResponseHandlers(handlers ...ResponseHandlerFunc)

AddResponseHandlers : adds some response handlers to the current response handlers.

func (*Client) Call

func (client *Client) Call(c *gin.Context, req Request) (Result, bool)

Call : direct call to the API.

type Request

type Request struct {
	Method                     string
	Endpoint                   string
	ContentType                string
	Authenticated              bool
	Body                       interface{}
	Response                   interface{}
	UseDefaultResponseHandlers bool
	ResponseHandlers           []ResponseHandlerFunc
}

Request : request of an API call.

func NewRequest

func NewRequest() (request Request)

NewRequest : returns a Request struct.

type ResponseHandlerFunc

type ResponseHandlerFunc func(c *gin.Context, statusCode int, requestError error, APIError response.Error) bool

ResponseHandlerFunc : handler for the API responses.

type Result

type Result struct {
	StatusCode   int
	RequestError error
	APIError     response.Error
	Handled      bool
}

Result : result of an API call.

type Status

type Status struct {
	Status string `json:"status"`
}

Status : result of an API call.

Jump to

Keyboard shortcuts

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