wemeethttp

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiRequest

type ApiRequest struct {
	ApiURI      string
	Body        interface{}
	PathParams  PathParams
	QueryParams QueryParams
	// contains filtered or unexported fields
}

func (*ApiRequest) GenerateURL

func (req *ApiRequest) GenerateURL(baseURL string) (*url.URL, error)

type ApiResponse

type ApiResponse struct {
	StatusCode int
	Header     http.Header
	RawBody    []byte
	// contains filtered or unexported fields
}

func (ApiResponse) Translate

func (resp ApiResponse) Translate(dst interface{}, opts ...ResponseOptionFunc) error

func (ApiResponse) Write

func (resp ApiResponse) Write(writer http.ResponseWriter) error

type Authentication

type Authentication interface {
	AuthHeader(httpReq *http.Request) error
}

Authentication 鉴权能力

type Client

type Client interface {
	Get(ctx context.Context, req *ApiRequest, opts ...RequestOptionFunc) (resp *ApiResponse, err error)
	Post(ctx context.Context, req *ApiRequest, opts ...RequestOptionFunc) (resp *ApiResponse, err error)
	Put(ctx context.Context, req *ApiRequest, opts ...RequestOptionFunc) (resp *ApiResponse, err error)
	Delete(ctx context.Context, req *ApiRequest, opts ...RequestOptionFunc) (resp *ApiResponse, err error)
}

Client 封装 REST 标准客户端接口

func NewClient

func NewClient(host string, opts ...ClientOptionFunc) (Client, error)

type ClientOptionFunc

type ClientOptionFunc func(c *client)

func WithClient

func WithClient(httpClt *http.Client) ClientOptionFunc

func WithProtocol

func WithProtocol(protocol string) ClientOptionFunc

func WithSerializer

func WithSerializer(serializer Serializable) ClientOptionFunc

type PathParams

type PathParams map[string]string

func (PathParams) Get

func (u PathParams) Get(key string) string

func (PathParams) Set

func (u PathParams) Set(key, value string)

type QueryParams

type QueryParams map[string][]string

func (QueryParams) Add

func (u QueryParams) Add(key, value string)

func (QueryParams) Encode

func (u QueryParams) Encode() string

func (QueryParams) Get

func (u QueryParams) Get(key string) string

func (QueryParams) GetAll

func (u QueryParams) GetAll(key string) []string

func (QueryParams) Set

func (u QueryParams) Set(key, value string)

type RequestOptionFunc

type RequestOptionFunc func(request *ApiRequest)

RequestOptionFunc ...

func WithRequestAuthenticator

func WithRequestAuthenticator(authenticator Authentication) RequestOptionFunc

func WithRequestHeader

func WithRequestHeader(header http.Header) RequestOptionFunc

func WithRequestSerializer

func WithRequestSerializer(serializer Serializable) RequestOptionFunc

type ResponseOptionFunc

type ResponseOptionFunc func(resp *ApiResponse)

func WithResponseSerializer

func WithResponseSerializer(serializer Serializable) ResponseOptionFunc

type Serializable

type Serializable interface {
	Name() string
	ContentType() string
	Serialize(v interface{}) ([]byte, error)
	Deserialize(data []byte, v interface{}) error
}

Serializable 序列化能力

Jump to

Keyboard shortcuts

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