Documentation ¶
Index ¶
- Constants
- Variables
- func EnableStackTraceErrorWrapf()
- func SetErrorWrapf(f func(err error, format string, args ...interface{}) error)
- type BkApiClient
- type BkApiClientOption
- type BkApiOption
- type BkApiRequestError
- type BodyProvider
- type ClientConfig
- type ClientConfigProvider
- type Operation
- type OperationConfig
- type OperationConfigProvider
- type OperationOption
- type ResultProvider
Constants ¶
const ( // UserAgent the default user agent header UserAgent = "bkapi-client-golang" // Version is the version of the package. Version = "0.0.0" )
Variables ¶
var ( // ErrTypeNotMatch defines the error which indicates the type of the value is not match. ErrTypeNotMatch = errors.New("type not match") // ErrBkApiRequest defines the error which indicates the api request error. ErrBkApiRequest = errors.New("bkapi request error") // ErrConfigInvalid defines the error which indicates the config is invalid. ErrConfigInvalid = errors.New("config invalid") )
var ( // ErrorWrapf annotates err with the format specifier and arguments. ErrorWrapf = pkgErrors.WithMessagef // ErrorCause returns the underlying cause of the error, if possible. ErrorCause = pkgErrors.Cause )
Functions ¶
func EnableStackTraceErrorWrapf ¶
func EnableStackTraceErrorWrapf()
EnableStackTraceErrorWrapf enables stack trace for ErrorWrapf.
func SetErrorWrapf ¶
SetErrorWrapf sets the ErrorWrapf. This function is not thread safe, do not call it in parallel.
Types ¶
type BkApiClient ¶
type BkApiClient interface { // Name method returns the client's name. Name() string // Apply method applies the given options to the client. Apply(opts ...BkApiClientOption) error // AddOperationOptions adds the common options to each operation. AddOperationOptions(opts ...OperationOption) error // NewOperation method creates a new operation dynamically and apply the given options. NewOperation(config OperationConfigProvider, opts ...OperationOption) Operation }
BkApiClient defines the interface of BkApi client.
type BkApiClientOption ¶
type BkApiClientOption interface { // ApplyToClient method applies the option to the client. ApplyToClient(client BkApiClient) error }
BkApiClientOption defines the interface of BkApi client option.
type BkApiOption ¶ added in v0.1.11
type BkApiOption interface { OperationOption BkApiClientOption }
BkApiOption combines OperationOption and BkApiClientOption.
type BkApiRequestError ¶
type BkApiRequestError interface { error RequestId() string ErrorCode() string ErrorMessage() string }
BkApiRequestError is the error returned by api gateway.
type BodyProvider ¶
type BodyProvider interface { // ProvideBody method will make the request body by data. ProvideBody(operation Operation, data interface{}) error }
BodyProvider defines the function to provide the request body.
type ClientConfig ¶
type ClientConfig interface { // GetName returns the name of the api GetName() string // GetUrl returns the url of the client. GetUrl() string // GetAuthorizationHeaders returns the authorization headers of the client. GetAuthorizationHeaders() map[string]string // GetLogger returns the client logger. GetLogger() logging.Logger // GetClientOptions returns the client options. GetClientOptions() []BkApiClientOption }
ClientConfig used to create a new BkApiClient.
type ClientConfigProvider ¶
type ClientConfigProvider interface { // ProvideConfig returns a ClientConfig instance. ProvideConfig(apiName string) ClientConfig }
ClientConfigProvider should provide a ClientConfig instance.
type Operation ¶
type Operation interface { // ClientName method returns the client's name. ClientName() string // Name method returns the operation's name. Name() string // FullName method returns the operation's name. FullName() string // Apply method applies the given options to the operation. Apply(opts ...OperationOption) Operation // SetHeaders method sets the request headers. // If the header is already set, it will be overwritten. SetHeaders(headers map[string]string) Operation // SetQueryParams method sets the request query parameters. SetQueryParams(params map[string]string) Operation // SetPathParams method sets the request path parameters. SetPathParams(params map[string]string) Operation // SetBodyReader method sets the request body. SetBodyReader(body io.Reader) Operation // SetBody method sets the data for body provider SetBody(data interface{}) Operation // SetBodyProvider method sets the request body provider. // A provider not only provides the request body, // but also provides the request headers, like Content-Type. SetBodyProvider(provider BodyProvider) Operation // SetResult method sets the operation result. SetResult(result interface{}) Operation // SetResultProvider method sets the operation result provider. // You can combine multiple decoders into one function, // choose the right one by the response status code or content type. SetResultProvider(provider ResultProvider) Operation // SetContext method sets the request context. SetContext(ctx context.Context) Operation // SetContentType method sets the request content type. SetContentType(contentType string) Operation // SetContentEncoding method sets the request content encoding. SetContentLength(contentLength int64) Operation // Request method sends the operation request and returns the response. Request() (*http.Response, error) }
Operation defines the operation of the API.
type OperationConfig ¶
type OperationConfig interface { // GetName returns the operation name. GetName() string // GetMethod returns the HTTP method of the operation. GetMethod() string // GetPath returns the HTTP path of the operation. GetPath() string }
OperationConfig used to configure the operation.
type OperationConfigProvider ¶
type OperationConfigProvider interface { // ProvideConfig returns a OperationConfig instance. ProvideConfig() OperationConfig }
OperationConfigProvider should provide a OperationConfig instance.
type OperationOption ¶
type OperationOption interface { // ApplyToOperation method applies the option to the operation. ApplyToOperation(operation Operation) error }
OperationOption defines the option of the operation.
type ResultProvider ¶
type ResultProvider interface { // ProvideResult method will decode the response body to result. ProvideResult(response *http.Response, result interface{}) error }
ResultProvider defines the function to provide the response result.