Documentation ¶
Index ¶
- Constants
- func Add[T any](source []T, targets ...[]T) []T
- func Copy[T any](source []T) []T
- func GeneralMultipartSerializer(form *MultipartForm) (io.Reader, string, error)
- func IsNil(source any) bool
- func JSONBodyDeserializer(body []byte, target any) (any, error)
- func JSONBodySerializer(body any) (io.Reader, error)
- func Kind(source any) reflect.Kind
- func SliceToMap[T comparable, R any](defaultValue R, source ...T) map[T]R
- func Sub[T comparable](source, target []T) []T
- type APIResponse
- type BodyDeserializer
- type BodySerializer
- type ClientWMiddlewares
- func (s *ClientWMiddlewares) AddMiddlewares(mwares ...*Interceptor)
- func (s *ClientWMiddlewares) ClearMiddlewares()
- func (s *ClientWMiddlewares) ContextTimeout() (context.Context, context.CancelFunc)
- func (s *ClientWMiddlewares) Delete(targetURL string) *ReqRespErr
- func (s *ClientWMiddlewares) DoNewRequest(ctx context.Context, header http.Header, method string, targetURL string) *ReqRespErr
- func (s *ClientWMiddlewares) DoNewRequestWithBodyOptions(ctx context.Context, header http.Header, method string, targetURL string, ...) *ReqRespErr
- func (s *ClientWMiddlewares) DoRequest(req *http.Request) *ReqRespErr
- func (s *ClientWMiddlewares) ForgetMiddlewares(mwares ...*Interceptor)
- func (s *ClientWMiddlewares) Get(targetURL string) *ReqRespErr
- func (s *ClientWMiddlewares) HTTPClient() *http.Client
- func (s *ClientWMiddlewares) Head(targetURL string) *ReqRespErr
- func (s *ClientWMiddlewares) Options(targetURL string) *ReqRespErr
- func (s *ClientWMiddlewares) Patch(targetURL, contentType string, body io.Reader) *ReqRespErr
- func (s *ClientWMiddlewares) Post(targetURL, contentType string, body io.Reader) *ReqRespErr
- func (s *ClientWMiddlewares) Put(targetURL, contentType string, body io.Reader) *ReqRespErr
- func (s *ClientWMiddlewares) RoundTrip(req *http.Request) (*http.Response, error)
- func (s *ClientWMiddlewares) SetHTTPClient(client *http.Client)
- type GenericCallbackWrapper
- type GenericHTTPClient
- type GenericSlice
- type Interceptor
- type MultipartForm
- type MultipartSerializer
- type PathParam
- type ReqRespErr
- type WithBody
- func PATCH[T any, R any](client *GenericHTTPClient, url string) WithBody[T, R]
- func POST[T any, R any](client *GenericHTTPClient, url string) WithBody[T, R]
- func PUT[T any, R any](client *GenericHTTPClient, url string) WithBody[T, R]
- func WithJSONSerializer[T any, R any](client *GenericHTTPClient, method string, relativeURL string, ...) WithBody[T, R]
- type WithMultipart
- func PATCHMultipart[R any](client *GenericHTTPClient, url string) WithMultipart[R]
- func POSTMultipart[R any](client *GenericHTTPClient, url string) WithMultipart[R]
- func PUTMultipart[R any](client *GenericHTTPClient, url string) WithMultipart[R]
- func WithMultipartSerializer[R any](client *GenericHTTPClient, method string, relativeURL string, ...) WithMultipart[R]
- type WithoutBody
Constants ¶
const (
DefaultTimeoutMillisecond = 30 * time.Second // default timeout in milliseconds
)
Variables ¶
This section is empty.
Functions ¶
func GeneralMultipartSerializer ¶
func GeneralMultipartSerializer(form *MultipartForm) (io.Reader, string, error)
GeneralMultipartSerializer Default Multipart Body serializer
func JSONBodyDeserializer ¶
JSONBodyDeserializer Default JSON Body deserializer
func JSONBodySerializer ¶
JSONBodySerializer Default JSON Body serializer
func SliceToMap ¶
func SliceToMap[T comparable, R any](defaultValue R, source ...T) map[T]R
func Sub ¶
func Sub[T comparable](source, target []T) []T
Types ¶
type APIResponse ¶
type APIResponse[R any] struct { ReqRespErr Response *R }
APIResponse Response with Error & Type
type BodyDeserializer ¶
BodyDeserializer Deserialize the body (for response)
type BodySerializer ¶
BodySerializer Serialize the body (for put/post/patch etc)
type ClientWMiddlewares ¶
type ClientWMiddlewares struct { TimeoutMillisecond int64 // contains filtered or unexported fields }
func NewClient ¶
func NewClient() *ClientWMiddlewares
func NewClientWithMiddlewares ¶
func NewClientWithMiddlewares(client *http.Client, mwares ...*Interceptor) *ClientWMiddlewares
func (*ClientWMiddlewares) AddMiddlewares ¶
func (s *ClientWMiddlewares) AddMiddlewares(mwares ...*Interceptor)
func (*ClientWMiddlewares) ClearMiddlewares ¶
func (s *ClientWMiddlewares) ClearMiddlewares()
func (*ClientWMiddlewares) ContextTimeout ¶
func (s *ClientWMiddlewares) ContextTimeout() (context.Context, context.CancelFunc)
func (*ClientWMiddlewares) Delete ¶
func (s *ClientWMiddlewares) Delete(targetURL string) *ReqRespErr
Delete HTTP Method Delete
func (*ClientWMiddlewares) DoNewRequest ¶
func (s *ClientWMiddlewares) DoNewRequest(ctx context.Context, header http.Header, method string, targetURL string) *ReqRespErr
DoNewRequest
func (*ClientWMiddlewares) DoNewRequestWithBodyOptions ¶
func (s *ClientWMiddlewares) DoNewRequestWithBodyOptions(ctx context.Context, header http.Header, method string, targetURL string, body io.Reader, contentType string) *ReqRespErr
DoNewRequestWithBodyOptions
func (*ClientWMiddlewares) DoRequest ¶
func (s *ClientWMiddlewares) DoRequest(req *http.Request) *ReqRespErr
DoRequest
func (*ClientWMiddlewares) ForgetMiddlewares ¶
func (s *ClientWMiddlewares) ForgetMiddlewares(mwares ...*Interceptor)
func (*ClientWMiddlewares) Get ¶
func (s *ClientWMiddlewares) Get(targetURL string) *ReqRespErr
Get HTTP Method Get
func (*ClientWMiddlewares) HTTPClient ¶
func (s *ClientWMiddlewares) HTTPClient() *http.Client
func (*ClientWMiddlewares) Head ¶
func (s *ClientWMiddlewares) Head(targetURL string) *ReqRespErr
Head HTTP Method Head
func (*ClientWMiddlewares) Options ¶
func (s *ClientWMiddlewares) Options(targetURL string) *ReqRespErr
Options HTTP Method Options
func (*ClientWMiddlewares) Patch ¶
func (s *ClientWMiddlewares) Patch(targetURL, contentType string, body io.Reader) *ReqRespErr
Patch HTTP Method Patch
func (*ClientWMiddlewares) Post ¶
func (s *ClientWMiddlewares) Post(targetURL, contentType string, body io.Reader) *ReqRespErr
Post HTTP Method Post
func (*ClientWMiddlewares) Put ¶
func (s *ClientWMiddlewares) Put(targetURL, contentType string, body io.Reader) *ReqRespErr
Put HTTP Method Put
func (*ClientWMiddlewares) SetHTTPClient ¶
func (s *ClientWMiddlewares) SetHTTPClient(client *http.Client)
type GenericCallbackWrapper ¶
type GenericCallbackWrapper[R any] struct { Callback func() R }
func NewCallbackWrapper ¶
func NewCallbackWrapper[R any](callback func() R) *GenericCallbackWrapper[R]
type GenericHTTPClient ¶
type GenericHTTPClient struct { DefaultHeader http.Header Serializer MultipartSerializer SerializerForJSON BodySerializer Deserializer BodyDeserializer BaseURL string // contains filtered or unexported fields }
func NewGenericHTTPClient ¶
func NewGenericHTTPClient(baseURL string) *GenericHTTPClient
NewGenericHTTPClient New a NewGenericHTTPClient instance
func NewGenericHTTPClientWithMiddlewares ¶
func NewGenericHTTPClientWithMiddlewares(baseURL string, simpleHTTP *ClientWMiddlewares) *GenericHTTPClient
NewGenericHTTPClientWithMiddlewares a GenericHTTPClient instance with a SimpleHTTP
func (*GenericHTTPClient) GetSimpleHTTP ¶
func (w *GenericHTTPClient) GetSimpleHTTP() *ClientWMiddlewares
type GenericSlice ¶
type GenericSlice[T comparable] []T
func GenericSliceFromSlice ¶
func GenericSliceFromSlice[T comparable](source []T) *GenericSlice[T]
func (*GenericSlice[E]) Append ¶
func (s *GenericSlice[E]) Append(item ...E) *GenericSlice[E]
func (*GenericSlice[E]) Concat ¶
func (s *GenericSlice[E]) Concat(slices ...[]E) *GenericSlice[E]
func (*GenericSlice[E]) Len ¶
func (s *GenericSlice[E]) Len() int
func (*GenericSlice[E]) RemoveItem ¶
func (s *GenericSlice[E]) RemoveItem(input ...E) *GenericSlice[E]
func (*GenericSlice[T]) ToArray ¶
func (s *GenericSlice[T]) ToArray() []T
type Interceptor ¶
type MultipartForm ¶
type MultipartForm struct { Value map[string][]string // File The absolute paths of files File map[string][]string }
MultipartForm Path params for API usages
type MultipartSerializer ¶
type MultipartSerializer func(body *MultipartForm) (io.Reader, string, error)
MultipartSerializer Serialize the multipart body (for put/post/patch etc)
type WithBody ¶
type WithBody[T any, R any] func(pathParam PathParam, body T, target *R) *GenericCallbackWrapper[*APIResponse[R]]
WithBody API with request body options
func WithJSONSerializer ¶
func WithJSONSerializer[T any, R any](client *GenericHTTPClient, method string, relativeURL string, contentType string, bodySerializer BodySerializer) WithBody[T, R]
type WithMultipart ¶
type WithMultipart[R any] func(pathParam PathParam, body *MultipartForm, target *R) *GenericCallbackWrapper[*APIResponse[R]]
WithMultipart API with request body options
func PATCHMultipart ¶
func PATCHMultipart[R any](client *GenericHTTPClient, url string) WithMultipart[R]
func POSTMultipart ¶
func POSTMultipart[R any](client *GenericHTTPClient, url string) WithMultipart[R]
func PUTMultipart ¶
func PUTMultipart[R any](client *GenericHTTPClient, url string) WithMultipart[R]
func WithMultipartSerializer ¶
func WithMultipartSerializer[R any](client *GenericHTTPClient, method string, relativeURL string, multipartSerializer MultipartSerializer) WithMultipart[R]
type WithoutBody ¶
type WithoutBody[R any] func(pathParam PathParam, target *R) *GenericCallbackWrapper[*APIResponse[R]]
WithoutBody API without request body options
func DELETE ¶
func DELETE[R any](client *GenericHTTPClient, url string) WithoutBody[R]
func DoNewRequest ¶
func DoNewRequest[R any](client *GenericHTTPClient, method string, relativeURL string) WithoutBody[R]
func GET ¶
func GET[R any](client *GenericHTTPClient, url string) WithoutBody[R]