options

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Module for setup AppConfig, ClientConfig

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultTransport                 = InitTransport()
	DefaultMakeReqFunc MakeReqFunc   = NewDefaultMakeReqFunc
	DefaultDecFunc     DecFunc       = NewDefaultDecFunc
	DefaultLocation                  = NewDefaultLocation()
	DefaultLogger      logger.Logger = logger.StdLogger
)

Functions

func DefaultAfterFunc

func DefaultAfterFunc(ctx context.Context, resp *http.Response) context.Context

DefaultAfterFunc log the response body

func DefaultBeforeFunc

func DefaultBeforeFunc(ctx context.Context, req *http.Request) context.Context

DefaultBeforeFunc log the request body

func EmptyAfterFunc

func EmptyAfterFunc(ctx context.Context, resp *http.Response) context.Context

EmptyAfterFunc do nothing

func EmptyBeforeFunc

func EmptyBeforeFunc(ctx context.Context, req *http.Request) context.Context

EmptyBeforeFunc do nothing

func InitTransport added in v0.2.2

func InitTransport() http.RoundTripper

func NewDefaultDecFunc

func NewDefaultDecFunc(ctx context.Context, input interface{}, result interface{}) (err error)

NewDefaultDecFunc encode json into target struct

func NewDefaultMakeReqFunc

func NewDefaultMakeReqFunc(ctx context.Context, method string, param m.M, c config.Config) (*http.Request, error)

NewDefaultMakeReqFunc default make request func

func SetDefaultDecFunc

func SetDefaultDecFunc(f DecFunc)

SetDefaultDecFunc Set Global Default DecFunc

func SetDefaultLocation

func SetDefaultLocation(f Option)

SetDefaultLocation Set Global Default Location

func SetDefaultLogger

func SetDefaultLogger(f logger.Logger)

SetDefaultLogger Set Global Default Logger

func SetDefaultMakeReqFunc

func SetDefaultMakeReqFunc(f MakeReqFunc)

SetDefaultMakeReqFunc Set Global Default MakeReqFunc

func SetDefaultTransport

func SetDefaultTransport(f http.RoundTripper)

SetDefaultTransport Set Global Default Transport

func WithoutBizContentMakeReqFunc added in v0.1.3

func WithoutBizContentMakeReqFunc(ctx context.Context, method string, param m.M, c config.Config) (*http.Request, error)

Types

type DecFunc

type DecFunc func(context.Context, interface{}, interface{}) error

DecFunc convert response body into a struct or map

type MakeReqFunc

type MakeReqFunc func(context context.Context, method string, m m.M, config config.Config) (*http.Request, error)

MakeReqFunc make request

type Option

type Option func(*Options)

func AppAuthToken

func AppAuthToken(appAuthToken string) Option

AppAuthToken set AppAuthToken

func AppCertBytes

func AppCertBytes(data []byte) Option

AppCertBytes set AppCertSn form bytes

func AppCertPath

func AppCertPath(path string) Option

AppCertPath set AppCertSn form path

func AppCertSn

func AppCertSn(sn string) Option

AppCertSn set AppCertSn

func AppId

func AppId(appId string) Option

AppId set AppId

func AppendAfterFunc

func AppendAfterFunc(f ...ResponseFunc) Option

AppendAfterFunc append a ResponseFunc after current list

func AppendBeforeFunc

func AppendBeforeFunc(f ...ReqFunc) Option

AppendBeforeFunc append a ReqFunc after current list

func AuthToken

func AuthToken(authToken string) Option

AuthToken set AuthToken

func DefaultCharset

func DefaultCharset() Option

DefaultCharset utf-8

func DefaultFormat

func DefaultFormat() Option

DefaultVersion JSON

func DefaultVersion

func DefaultVersion() Option

DefaultVersion 1.0

func DisableLog

func DisableLog() Option

DisableLog set NullLogger

func NewDefaultLocation

func NewDefaultLocation() Option

NewDefaultLocation set location as Asia/Shanghai

func NotifyUrl

func NotifyUrl(notifyUrl string) Option

NotifyUrl set NotifyUrl

func PrivateKey

func PrivateKey(privateKey string) Option

PrivateKey set PrivateKey string

func PrivateKeyType

func PrivateKeyType(privateKeyType string) Option

PrivateKey set PrivateKeyType

func Production

func Production(input bool) Option

Production set Production flag

func PublicCertBytes

func PublicCertBytes(data []byte) Option

PublicCertBytes set PublicCertSn from bytes

func PublicCertPath

func PublicCertPath(path string) Option

PublicCertPath set PublicCertSn from path

func PublicCertSn

func PublicCertSn(sn string) Option

PublicCertSn set PublicCertSn

func ReturnUrl

func ReturnUrl(returnUrl string) Option

ReturnUrl set ReturnUrl

func RootCertBytes

func RootCertBytes(data []byte) Option

RootCertBytes set RootCertSn from bytes

func RootCertPath

func RootCertPath(path string) Option

RootCertPath set RootCertSn from path

func RootCertSn

func RootCertSn(sn string) Option

RootCertSn set RootCertSn

func SetAfterFunc

func SetAfterFunc(f ...ResponseFunc) Option

SetAfterFunc set ResponseFunc

func SetBeforeFunc

func SetBeforeFunc(f ...ReqFunc) Option

SetBeforeFunc set ReqFunc

func SetLocation

func SetLocation(loc *time.Location) Option

SetLocation time.Location

func SetLogger

func SetLogger(Logger logger.Logger) Option

SetLogger set logger

func SetMakeReqFunc added in v0.1.3

func SetMakeReqFunc(f MakeReqFunc) Option

SetMakeReqFunc set MakeRequestFunc

func SignType

func SignType(signType string) Option

SignType set SignType

func Transport

func Transport(transport http.RoundTripper) Option

Transport set Transport

type Options

type Options struct {
	Config config.Config

	// hooks
	Before []ReqFunc
	After  []ResponseFunc

	Dec     DecFunc
	MakeReq MakeReqFunc

	// other custom options
	// can be stored in a context
	Context context.Context

	Transport http.RoundTripper

	Logger logger.Logger
}

Options for alipay sdk

func DefaultOptions

func DefaultOptions(opts ...Option) Options

DefaultOptions set DefaultAfterFunc, DefaultBeforeFunc, DefaultLogger

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions

func (Options) Copy

func (o Options) Copy() Options

Copy create a current Options' Copy

type ReqFunc

type ReqFunc func(context context.Context, req *http.Request) context.Context

ReqFunc a hook Before the request started

type ResponseFunc

type ResponseFunc func(context context.Context, response *http.Response) context.Context

ResponseFunc a hook After the request finished

Jump to

Keyboard shortcuts

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