galf

package module
v0.0.0-...-b9174d0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2019 License: MIT Imports: 14 Imported by: 0

README

GALF

Go OAuth2 Client

Installation

Assuming you have a working Go environment:

go get github.com/globocom/galf

Documentation

Index

Constants

View Source
const (
	DefaultClientTimeout    = 20 * time.Second
	DefaultClientMaxRetries = 2
	DefaultContentType      = "application/json"
)
View Source
const (
	DefaultTokenMaxRetries    = 2
	DefaultTokenClientTimeout = 1 * time.Second
)

Variables

View Source
var TokenExpiredError = errors.New("Token expired")

Functions

func ConstantBackOff

func ConstantBackOff(_ int) time.Duration

ConstantBackOff always returns 30 Millisecond

func ExponentialBackoff

func ExponentialBackoff(i int) time.Duration

ExponentialBackoff returns ever increasing backoffs by a power of 2 in seconds

func HystrixConfigureCommand

func HystrixConfigureCommand(configName string, config hystrix.CommandConfig)

ConfigureCommand applies settings for a circuit

func LinearBackoff

func LinearBackoff(i int) time.Duration

LinearBackoff returns increasing durations, each a second longer than the last n seconds where n is the retry number

func NewRequestOptions

func NewRequestOptions() *requestOptions

func SetDefaultTokenManager

func SetDefaultTokenManager(tokenManager TokenManager)

Types

type BackoffStrategy

type BackoffStrategy func(retry int) time.Duration

BackoffStrategy is used to determine how long a retry request should wait until attempted

type Client

type Client struct {
	TokenManager TokenManager
	Options      ClientOptions
	// contains filtered or unexported fields
}

func NewClient

func NewClient(options ...ClientOptions) *Client

func NewClientCustom

func NewClientCustom(tokenManager TokenManager, options ClientOptions) *Client

func (*Client) Delete

func (c *Client) Delete(url string, reqOptions ...*requestOptions) (*goreq.Response, error)

func (*Client) Get

func (c *Client) Get(url string, reqOptions ...*requestOptions) (*goreq.Response, error)

func (*Client) Post

func (c *Client) Post(url string, body interface{}, reqOptions ...*requestOptions) (*goreq.Response, error)

func (*Client) Put

func (c *Client) Put(url string, body interface{}, reqOptions ...*requestOptions) (*goreq.Response, error)

type ClientOptions

type ClientOptions struct {
	ContentType   string
	Timeout       time.Duration
	Backoff       BackoffStrategy
	MaxRetries    int
	ShowDebug     bool
	HystrixConfig *HystrixConfig
}

func NewClientOptions

func NewClientOptions(timeout time.Duration, debug bool, maxRetries int, hystrixConfigName string, backoff ...BackoffStrategy) ClientOptions

type HTTP

type HTTP struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func NewHttpError

func NewHttpError(code int, message string) *HTTP

func (*HTTP) Error

func (e *HTTP) Error() string

type HystrixConfig

type HystrixConfig struct {
	Name string
	// contains filtered or unexported fields
}

func NewHystrixConfig

func NewHystrixConfig(configName string) *HystrixConfig

type OAuthTokenManager

type OAuthTokenManager struct {
	TokenEndPoint string
	ClientId      string
	ClientSecret  string
	Authorization string
	Options       TokenOptions
	// contains filtered or unexported fields
}

func NewTokenManager

func NewTokenManager(tokenEndPoint string, clientId string, clientSecret string, options ...TokenOptions) *OAuthTokenManager

func (*OAuthTokenManager) GetToken

func (tm *OAuthTokenManager) GetToken() (*Token, error)

func (*OAuthTokenManager) ResetToken

func (tm *OAuthTokenManager) ResetToken()

type Token

type Token struct {
	AccessToken   string `json:"access_token"`
	TokenType     string `json:"token_type"`
	ExpiresIn     int    `json:"expires_in"`
	Authorization string
	// contains filtered or unexported fields
}

type TokenManager

type TokenManager interface {
	GetToken() (*Token, error)
	ResetToken()
}

type TokenOptions

type TokenOptions struct {
	Timeout       time.Duration
	Backoff       BackoffStrategy
	MaxRetries    int
	ShowDebug     bool
	HystrixConfig *HystrixConfig
}

func NewTokenOptions

func NewTokenOptions(timeout time.Duration, debug bool, maxRetries int, circuitName string, backoff ...BackoffStrategy) TokenOptions

Jump to

Keyboard shortcuts

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