bkapi

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: MIT Imports: 26 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBkApiClient

func NewBkApiClient(
	apiName string,
	configProvider define.ClientConfigProvider,
	opts ...define.BkApiClientOption,
) (define.BkApiClient, error)

NewBkApiClient creates a new BkApiClient.

func OptAddCookie

func OptAddCookie(cookie *http.Cookie) define.BkApiOption

OptAddCookie adds a cookie to the request. Per RFC 6265 section 5.4, AddCookie does not attach more than one Cookie header field. That means all cookies, if any, are written into the same line, separated by semicolon.

func OptAddRequestQueryParam

func OptAddRequestQueryParam(key string, value string) define.BkApiOption

OptAddRequestQueryParam adds the query param value to key. It appends to any existing values associated with key.

func OptAddRequestQueryParamList added in v0.1.9

func OptAddRequestQueryParamList(key string, values []string) define.BkApiOption

OptAddRequestQueryParamList adds the query param value list to key. It appends to any existing values associated with key.

func OptBasicAuth

func OptBasicAuth(username, password string) define.BkApiOption

OptBasicAuth defines an authorization basic header in the outgoing request

func OptBearerAuth

func OptBearerAuth(token string) define.BkApiOption

OptBearerAuth defines an authorization bearer token header in the outgoing request

func OptDelAllCookies

func OptDelAllCookies() define.BkApiOption

OptDelAllCookies deletes all the cookies by deleting the Cookie header field.

func OptDelRequestHeader

func OptDelRequestHeader(key string) define.BkApiOption

OptDelRequestHeader deletes the header fields associated with key.

func OptDelRequestQueryParam

func OptDelRequestQueryParam(key string) define.BkApiOption

OptDelRequestQueryParam deletes the query param values associated with key.

func OptDialTimeout

func OptDialTimeout(duration, keepAlive time.Duration) define.BkApiOption

OptDialTimeout defines the maximum amount of time waiting for network dialing

func OptErrorCallback added in v0.1.10

func OptErrorCallback(fn func(err error) error) define.BkApiOption

OptErrorCallback sets the callback function for the error.

func OptLimitRedirect

func OptLimitRedirect(limit int) define.BkApiOption

OptLimitRedirect defines in the maximum number of redirects that http.Client should follow.

func OptProxies

func OptProxies(servers map[string]string) define.BkApiOption

OptProxies defines the proxy servers to be used based on the transport scheme

func OptRequestCallback added in v0.1.10

func OptRequestCallback(fn func(request *http.Request) *http.Request) define.BkApiOption

OptRequestCallback sets the callback function for the request.

func OptResponseCallback added in v0.1.10

func OptResponseCallback(fn func(response *http.Response) *http.Response) define.BkApiOption

OptResponseCallback sets the callback function for the response.

func OptSetRequestBody

func OptSetRequestBody(data interface{}) define.OperationOption

OptSetRequestBody sets the body of the operation.

func OptSetRequestHeader

func OptSetRequestHeader(key string, value string) define.BkApiOption

OptSetRequestHeader sets the header entries associated with key to the single element value. It replaces any existing values associated with key.

func OptSetRequestHeaders

func OptSetRequestHeaders(header map[string]string) define.BkApiOption

OptSetRequestHeaders sets the headers.

func OptSetRequestPathParams

func OptSetRequestPathParams(params map[string]string) define.OperationOption

OptSetRequestPathParams sets the path parameters of the operation.

func OptSetRequestQueryParam

func OptSetRequestQueryParam(key string, value string) define.BkApiOption

OptSetRequestQueryParam ets the query param key and value. It replaces any existing values.

func OptSetRequestQueryParams

func OptSetRequestQueryParams(params map[string]string) define.BkApiOption

OptSetRequestQueryParams sets the query params.

func OptSetRequestResult

func OptSetRequestResult(result interface{}) define.OperationOption

OptSetRequestResult sets the result of the operation.

func OptTLS

func OptTLS(config *tls.Config) define.BkApiOption

OptTLS defines the request TLS connection config

func OptTLShandshakeTimeout

func OptTLShandshakeTimeout(duration time.Duration) define.BkApiOption

OptTLShandshakeTimeout defines the maximum amount of time waiting for a TLS handshake

func OptTimeout

func OptTimeout(duration time.Duration) define.BkApiOption

OptTimeout defines the maximum amount of time a whole request process (including dial / request / redirect) can take.

func OptTransport

func OptTransport(roundTripper http.RoundTripper) define.BkApiOption

OptTransport sets a new HTTP transport for the outgoing request

Types

type ClientConfig

type ClientConfig struct {

	// Endpoint is the url of the BkApi server.
	Endpoint string
	// Stage is the api stage name, defaults to "prod".
	Stage string

	// AppCode is the blueking app code.
	AppCode string
	// AppSecret is the secret key of the blueking app.
	AppSecret string

	// AccessToken is the access token of the user and app, optional.
	AccessToken string
	// AuthorizationParams is the authorization params of the user and app, optional.
	AuthorizationParams map[string]string
	// AuthorizationJWT is the bkapi jwt, optional.
	AuthorizationJWT string
	// JsonMarshal is the json marshal function, defaults to json.Marshal.
	JsonMarshaler func(v interface{}) ([]byte, error)

	// Getenv is the function to get env, defaults to os.Getenv.
	Getenv func(string) string

	// Logger is used to log the request and response.
	Logger logging.Logger
	// contains filtered or unexported fields
}

ClientConfig is the configuration of BkApi client.

func (*ClientConfig) GetAuthorizationHeaders

func (c *ClientConfig) GetAuthorizationHeaders() map[string]string

GetAuthorizationHeaders method will return the authorization headers.

func (*ClientConfig) GetLogger

func (c *ClientConfig) GetLogger() logging.Logger

GetLogger method will return the logger.

func (*ClientConfig) GetName

func (c *ClientConfig) GetName() string

GetName method will return the api name.

func (*ClientConfig) GetUrl

func (c *ClientConfig) GetUrl() string

GetUrl method will render the endpoint with api name and stage.

func (ClientConfig) ProvideConfig

func (c ClientConfig) ProvideConfig(apiName string) define.ClientConfig

ProvideConfig method clone and return a new Config instance. This method should fill the default values which are not set.

type FormMarshalBodyProvider

type FormMarshalBodyProvider struct {
	*MarshalBodyProvider
}

FormMarshalBodyProvider provides request body as urlencoded form.

func FormBodyProvider

func FormBodyProvider() *FormMarshalBodyProvider

FormBodyProvider is a function to set form body from map[string][]string

func NewFormMarshalBodyProvider

func NewFormMarshalBodyProvider(marshaler func(v interface{}) ([]byte, error)) *FormMarshalBodyProvider

NewFormMarshalBodyProvider creates a new FormMarshalBodyProvider with marshal function.

func OptFormBodyProvider

func OptFormBodyProvider() *FormMarshalBodyProvider

OptFormBodyProvider is a function to set form body

type FunctionalBodyProvider

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

FunctionalBodyProvider provides the request body by the given function.

func NewFunctionalBodyProvider

func NewFunctionalBodyProvider(fn func(operation define.Operation, data interface{}) error) *FunctionalBodyProvider

NewFunctionalBodyProvider creates a new BodyProvider with the given function.

func (*FunctionalBodyProvider) ApplyToClient

func (p *FunctionalBodyProvider) ApplyToClient(cli define.BkApiClient) error

ApplyToClient will add to the operation operations.

func (*FunctionalBodyProvider) ApplyToOperation

func (p *FunctionalBodyProvider) ApplyToOperation(op define.Operation) error

ApplyToOperation will set the body provider.

func (*FunctionalBodyProvider) ProvideBody

func (p *FunctionalBodyProvider) ProvideBody(operation define.Operation, data interface{}) error

ProvideBody method calls the given function to provide the request body.

type JsonMarshalBodyProvider

type JsonMarshalBodyProvider struct {
	*MarshalBodyProvider
}

JsonMarshalBodyProvider provides request body as json.

func JsonBodyProvider

func JsonBodyProvider() *JsonMarshalBodyProvider

JsonBodyProvider creates a new JsonMarshalBodyProvider with default marshal function.

func NewJsonMarshalBodyProvider

func NewJsonMarshalBodyProvider(marshaler func(v interface{}) ([]byte, error)) *JsonMarshalBodyProvider

NewJsonMarshalBodyProvider creates a new JsonMarshalBodyProvider with marshal function.

func OptJsonBodyProvider

func OptJsonBodyProvider() *JsonMarshalBodyProvider

OptJsonBodyProvider is a option for json body provider.

type JsonUnmarshalResultProvider

type JsonUnmarshalResultProvider struct {
	*UnmarshalResultProvider
}

JsonUnmarshalResultProvider provides result from json.

func JsonResultProvider

func JsonResultProvider() *JsonUnmarshalResultProvider

JsonResultProvider creates a new JsonUnmarshalResultProvider with default unmarshal function.

func NewJsonUnmarshalResultProvider

func NewJsonUnmarshalResultProvider(
	unmarshaler func(body io.Reader, v interface{}) error,
) *JsonUnmarshalResultProvider

NewJsonUnmarshalResultProvider creates a new JsonUnmarshalResultProvider with unmarshal function.

func OptJsonResultProvider

func OptJsonResultProvider() *JsonUnmarshalResultProvider

OptJsonResultProvider is a option for json result provider.

type MarshalBodyProvider

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

MarshalBodyProvider wraps the marshal function to provide the request body.

func NewMarshalBodyProvider

func NewMarshalBodyProvider(contentType string, marshalFn func(v interface{}) ([]byte, error)) *MarshalBodyProvider

NewMarshalBodyProvider creates a new BodyProvider with the given content type and marshal function.

func (*MarshalBodyProvider) ApplyToClient

func (m *MarshalBodyProvider) ApplyToClient(cli define.BkApiClient) error

ApplyToClient will add to the operation operations.

func (*MarshalBodyProvider) ApplyToOperation

func (m *MarshalBodyProvider) ApplyToOperation(op define.Operation) error

ApplyToOperation will set the body provider.

func (*MarshalBodyProvider) ContentType

func (m *MarshalBodyProvider) ContentType() string

ContentType returns the Content-Type of the request body.

func (*MarshalBodyProvider) ProvideBody

func (m *MarshalBodyProvider) ProvideBody(operation define.Operation, data interface{}) error

ProvideBody method provides the request body, and returns the content length.

type MultipartFormFieldsBodyProvider

type MultipartFormFieldsBodyProvider struct {
	*FunctionalBodyProvider
}

MultipartFormFieldsBodyProvider provides request body as multipart form.

func MultipartFormBodyProvider

func MultipartFormBodyProvider() *MultipartFormFieldsBodyProvider

MultipartFormBodyProvider provides request body as multipart form.

func NewMultipartFormFieldsBodyProvider

func NewMultipartFormFieldsBodyProvider() *MultipartFormFieldsBodyProvider

NewMultipartFormFieldsBodyProvider create a new MultipartFormFieldsBodyProvider

func OptMultipartFormBodyProvider

func OptMultipartFormBodyProvider() *MultipartFormFieldsBodyProvider

OptMultipartFormBodyProvider provides request body as multipart form.

type OperationConfig

type OperationConfig struct {
	// Name is the operation name.
	Name string
	// Method is the HTTP method of the operation.
	Method string
	// Path is the HTTP path of the operation.
	Path string
}

OperationConfig used to configure the operation.

func (*OperationConfig) GetMethod

func (c *OperationConfig) GetMethod() string

GetMethod returns the HTTP method of the operation.

func (*OperationConfig) GetName

func (c *OperationConfig) GetName() string

GetName returns the operation name.

func (*OperationConfig) GetPath

func (c *OperationConfig) GetPath() string

GetPath returns the HTTP path of the operation.

func (OperationConfig) ProvideConfig

func (c OperationConfig) ProvideConfig() define.OperationConfig

ProvideConfig clone and returns a new OperationConfig.

type OperationOption

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

OperationOption is a wrapper for a operation option.

func NewOperationOption

func NewOperationOption(fn func(operation define.Operation) error) *OperationOption

NewOperationOption creates a new OperationOption.

func (*OperationOption) ApplyToClient

func (o *OperationOption) ApplyToClient(client define.BkApiClient) error

ApplyToClient will apply the given options to the client.

func (*OperationOption) ApplyToOperation

func (o *OperationOption) ApplyToOperation(op define.Operation) error

ApplyToOperation will check if the operation is valid and apply the option to the operation.

type UnmarshalResultProvider

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

UnmarshalResultProvider wraps the unmarshal function to provide result from the response body.

func NewUnmarshalResultProvider

func NewUnmarshalResultProvider(fn func(body io.Reader, v interface{}) error) *UnmarshalResultProvider

NewUnmarshalResultProvider creates a new ResultProvider with the given unmarshal function.

func (*UnmarshalResultProvider) ApplyToClient

func (p *UnmarshalResultProvider) ApplyToClient(cli define.BkApiClient) error

ApplyToClient will add to the operation operations.

func (*UnmarshalResultProvider) ApplyToOperation

func (p *UnmarshalResultProvider) ApplyToOperation(op define.Operation) error

ApplyToOperation will set the result provider.

func (*UnmarshalResultProvider) ProvideResult

func (p *UnmarshalResultProvider) ProvideResult(response *http.Response, result interface{}) error

ProvideResult method provides the result from the response body.

Jump to

Keyboard shortcuts

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