utils

package
v1.0.0-beta5 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2019 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Overview

Package utils //

Package utils //

Package utils //

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBoolValue

func GetBoolValue(value interface{}) (bool, error)

GetBoolValue will attempt to convert the given value to a bool

func GetFloatValue

func GetFloatValue(value interface{}) (float64, error)

GetFloatValue will attempt to convert the given value to a float64

func GetIntValue

func GetIntValue(value interface{}) (int64, error)

GetIntValue will attempt to convert the given value to an int64

func GetStringValue

func GetStringValue(value interface{}) (string, error)

GetStringValue will attempt to convert the given value to a string

func Headers

func Headers(headers ...Header) func(r *HTTPRequester)

Headers sets request headers

func Retries

func Retries(retries int) func(r *HTTPRequester)

Retries sets max number of retries for failed calls

func Timeout

func Timeout(timeout time.Duration) func(r *HTTPRequester)

Timeout sets http client timeout

Types

type CancelableExecutionCtx

type CancelableExecutionCtx struct {
	Wg         *sync.WaitGroup
	Ctx        context.Context
	CancelFunc context.CancelFunc
}

CancelableExecutionCtx has WithCancel implementation

func NewCancelableExecutionCtx

func NewCancelableExecutionCtx() *CancelableExecutionCtx

NewCancelableExecutionCtx returns constructed object

func (CancelableExecutionCtx) GetContext

func (ctx CancelableExecutionCtx) GetContext() context.Context

GetContext is context getter

func (CancelableExecutionCtx) GetWaitSync

func (ctx CancelableExecutionCtx) GetWaitSync() *sync.WaitGroup

GetWaitSync is waitgroup getter

func (CancelableExecutionCtx) TerminateAndWait

func (ctx CancelableExecutionCtx) TerminateAndWait()

TerminateAndWait sends termination signal and waits

type ExecutionCtx

type ExecutionCtx interface {
	TerminateAndWait()
	GetContext() context.Context
	GetWaitSync() *sync.WaitGroup
}

ExecutionCtx is the interface, user can overwrite it

type HTTPRequester

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

HTTPRequester contains main info

func NewHTTPRequester

func NewHTTPRequester(url string, params ...func(*HTTPRequester)) *HTTPRequester

NewHTTPRequester makes Requester with api and parameters. Sets defaults url has a complete url of the request like https://cdn.optimizely.com/datafiles/24234.json

func (HTTPRequester) Do

func (r HTTPRequester) Do(method string, body io.Reader, headers []Header) (response []byte, code int, err error)

Do executes request and returns response body for requested uri (sdkKey.json).

func (HTTPRequester) Get

func (r HTTPRequester) Get(headers ...Header) (response []byte, code int, err error)

Get executes HTTP GET with url and optional extra headers, returns body in []bytes url created as url+sdkKey.json

func (HTTPRequester) GetObj

func (r HTTPRequester) GetObj(result interface{}, headers ...Header) error

GetObj executes HTTP GET with url and optional extra headers, returns filled object

func (HTTPRequester) Post

func (r HTTPRequester) Post(body interface{}, headers ...Header) (response []byte, code int, err error)

Post executes HTTP POST with url, body and optional extra headers

func (HTTPRequester) PostObj

func (r HTTPRequester) PostObj(body, result interface{}, headers ...Header) error

PostObj executes HTTP POST with uri, body and optional extra headers. Returns filled object

func (HTTPRequester) String

func (r HTTPRequester) String() string
type Header struct {
	Name, Value string
}

Header element to be sent

type Requester

type Requester interface {
	Get(...Header) (response []byte, code int, err error)
	GetObj(result interface{}, headers ...Header) error

	Post(body interface{}, headers ...Header) (response []byte, code int, err error)
	PostObj(body interface{}, result interface{}, headers ...Header) error

	String() string
}

Requester is used to make outbound requests with

Jump to

Keyboard shortcuts

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