network

package
v2.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeoutMillisecond Default Request TimeoutMillisecond
	DefaultTimeoutMillisecond = 30 * time.Second
)

Variables

This section is empty.

Functions

func GeneralMultipartSerializer

func GeneralMultipartSerializer(form *MultipartForm) (io.Reader, string, error)

GeneralMultipartSerializer Default Multipart Body serializer

func JSONBodyDeserializer

func JSONBodyDeserializer(body []byte, target interface{}) (interface{}, error)

JSONBodyDeserializer Default JSON Body deserializer

func JSONBodySerializer

func JSONBodySerializer(body interface{}) (io.Reader, error)

JSONBodySerializer Default JSON Body serializer

Types

type APIHasBody

type APIHasBody[T any, R any] func(pathParam PathParam, body T, target *R) *fpgo.MonadIODef[*APIResponse[R]]

APIHasBody API with request body options

func APIMakeDoNewRequestWithBodySerializer

func APIMakeDoNewRequestWithBodySerializer[T any, R any](simpleAPISelf *SimpleAPIDef, method string, relativeURL string, contentType string, bodySerializer BodySerializer) APIHasBody[T, R]

APIMakeDoNewRequestWithBodySerializer Make a API with request body options

func APIMakePatchJSONBody

func APIMakePatchJSONBody[T any, R any](simpleAPISelf *SimpleAPIDef, relativeURL string) APIHasBody[T, R]

APIMakePatchJSONBody Make a Patch API with json Body

func APIMakePostJSONBody

func APIMakePostJSONBody[T any, R any](simpleAPISelf *SimpleAPIDef, relativeURL string) APIHasBody[T, R]

APIMakePostJSONBody Make a Post API with json Body

func APIMakePutJSONBody

func APIMakePutJSONBody[T any, R any](simpleAPISelf *SimpleAPIDef, relativeURL string) APIHasBody[T, R]

APIMakePutJSONBody Make a Put API with json Body

type APIMultipart

type APIMultipart[R any] func(pathParam PathParam, body *MultipartForm, target *R) *fpgo.MonadIODef[*APIResponse[R]]

APIMultipart API with request body options

func APIMakeDoNewRequestWithMultipartSerializer

func APIMakeDoNewRequestWithMultipartSerializer[R any](simpleAPISelf *SimpleAPIDef, method string, relativeURL string, multipartSerializer MultipartSerializer) APIMultipart[R]

APIMakeDoNewRequestWithMultipartSerializer Make a API with request body options

func APIMakePatchMultipartBody

func APIMakePatchMultipartBody[R any](simpleAPISelf *SimpleAPIDef, relativeURL string) APIMultipart[R]

APIMakePatchMultipartBody Make a Patch API with multipart Body

func APIMakePostMultipartBody

func APIMakePostMultipartBody[R any](simpleAPISelf *SimpleAPIDef, relativeURL string) APIMultipart[R]

APIMakePostMultipartBody Make a Post API with multipart Body

func APIMakePutMultipartBody

func APIMakePutMultipartBody[R any](simpleAPISelf *SimpleAPIDef, relativeURL string) APIMultipart[R]

APIMakePutMultipartBody Make a Put API with multipart Body

type APINoBody

type APINoBody[R any] func(pathParam PathParam, target *R) *fpgo.MonadIODef[*APIResponse[R]]

APINoBody API without request body options

func APIMakeDelete

func APIMakeDelete[R any](simpleAPISelf *SimpleAPIDef, relativeURL string) APINoBody[R]

APIMakeDelete Make a Delete API

func APIMakeDoNewRequest

func APIMakeDoNewRequest[R any](simpleAPISelf *SimpleAPIDef, method string, relativeURL string) APINoBody[R]

APIMakeDoNewRequest Make a API without body options

func APIMakeGet

func APIMakeGet[R any](simpleAPISelf *SimpleAPIDef, relativeURL string) APINoBody[R]

APIMakeGet Make a Get API

type APIResponse

type APIResponse[R any] struct {
	ResponseWithError
	TargetObject *R
}

APIResponse Response with Error & Type

type BodyDeserializer

type BodyDeserializer func(body []byte, target interface{}) (interface{}, error)

BodyDeserializer Deserialize the body (for response)

type BodySerializer

type BodySerializer func(body interface{}) (io.Reader, error)

BodySerializer Serialize the body (for put/post/patch etc)

type Interceptor

type Interceptor func(*http.Request) error

Interceptor Interceptor functions

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 PathParam

type PathParam map[string]interface{}

PathParam Path params for API usages

type ResponseWithError

type ResponseWithError struct {
	Request  *http.Request
	Response *http.Response

	Err error
}

ResponseWithError Response with Error

type SimpleAPIDef

type SimpleAPIDef struct {
	BaseURL       string
	DefaultHeader http.Header

	RequestSerializerForMultipart MultipartSerializer
	RequestSerializerForJSON      BodySerializer
	ResponseDeserializer          BodyDeserializer
	// contains filtered or unexported fields
}

SimpleAPIDef SimpleAPIDef inspired by Retrofits

func NewSimpleAPI

func NewSimpleAPI(baseURL string) *SimpleAPIDef

NewSimpleAPI New a NewSimpleAPI instance

func NewSimpleAPIWithSimpleHTTP

func NewSimpleAPIWithSimpleHTTP(baseURL string, simpleHTTP *SimpleHTTPDef) *SimpleAPIDef

NewSimpleAPIWithSimpleHTTP a SimpleAPIDef instance with a SimpleHTTP

func (*SimpleAPIDef) GetSimpleHTTP

func (simpleAPISelf *SimpleAPIDef) GetSimpleHTTP() *SimpleHTTPDef

GetSimpleHTTP Get the SimpleHTTP

type SimpleHTTPDef

type SimpleHTTPDef struct {
	TimeoutMillisecond int64
	// contains filtered or unexported fields
}

SimpleHTTPDef SimpleHTTP inspired by Retrofits

func NewSimpleHTTP

func NewSimpleHTTP() *SimpleHTTPDef

NewSimpleHTTP New a SimpleHTTP instance

func NewSimpleHTTPWithClientAndInterceptors

func NewSimpleHTTPWithClientAndInterceptors(client *http.Client, interceptors ...*Interceptor) *SimpleHTTPDef

NewSimpleHTTPWithClientAndInterceptors a SimpleHTTP instance with a given client & interceptor(s)

func (*SimpleHTTPDef) AddInterceptor

func (simpleHTTPSelf *SimpleHTTPDef) AddInterceptor(interceptors ...*Interceptor)

AddInterceptor Add the interceptor(s)

func (*SimpleHTTPDef) ClearInterceptor

func (simpleHTTPSelf *SimpleHTTPDef) ClearInterceptor()

ClearInterceptor Clear the interceptor(s)

func (*SimpleHTTPDef) Delete

func (simpleHTTPSelf *SimpleHTTPDef) Delete(givenURL string) *ResponseWithError

Delete HTTP Method Delete

func (*SimpleHTTPDef) DoNewRequest

func (simpleHTTPSelf *SimpleHTTPDef) DoNewRequest(context context.Context, header http.Header, method string, givenURL string) *ResponseWithError

DoNewRequest Do New HTTP Request

func (*SimpleHTTPDef) DoNewRequestWithBodyOptions

func (simpleHTTPSelf *SimpleHTTPDef) DoNewRequestWithBodyOptions(context context.Context, header http.Header, method string, givenURL string, body io.Reader, contentType string) *ResponseWithError

DoNewRequestWithBodyOptions Do New HTTP Request with body options

func (*SimpleHTTPDef) DoRequest

func (simpleHTTPSelf *SimpleHTTPDef) DoRequest(request *http.Request) *ResponseWithError

DoRequest Do HTTP Request with interceptors

func (*SimpleHTTPDef) Get

func (simpleHTTPSelf *SimpleHTTPDef) Get(givenURL string) *ResponseWithError

Get HTTP Method Get

func (*SimpleHTTPDef) GetContextTimeout

func (simpleHTTPSelf *SimpleHTTPDef) GetContextTimeout() (context.Context, context.CancelFunc)

GetContextTimeout Get Context by TimeoutMillisecond

func (*SimpleHTTPDef) GetHTTPClient

func (simpleHTTPSelf *SimpleHTTPDef) GetHTTPClient() *http.Client

GetHTTPClient Get the http client

func (*SimpleHTTPDef) Head

func (simpleHTTPSelf *SimpleHTTPDef) Head(givenURL string) *ResponseWithError

Head HTTP Method Head

func (*SimpleHTTPDef) Options

func (simpleHTTPSelf *SimpleHTTPDef) Options(givenURL string) *ResponseWithError

Options HTTP Method Options

func (*SimpleHTTPDef) Patch

func (simpleHTTPSelf *SimpleHTTPDef) Patch(givenURL, contentType string, body io.Reader) *ResponseWithError

Patch HTTP Method Patch

func (*SimpleHTTPDef) Post

func (simpleHTTPSelf *SimpleHTTPDef) Post(givenURL, contentType string, body io.Reader) *ResponseWithError

Post HTTP Method Post

func (*SimpleHTTPDef) Put

func (simpleHTTPSelf *SimpleHTTPDef) Put(givenURL, contentType string, body io.Reader) *ResponseWithError

Put HTTP Method Put

func (*SimpleHTTPDef) RemoveInterceptor

func (simpleHTTPSelf *SimpleHTTPDef) RemoveInterceptor(interceptors ...*Interceptor)

RemoveInterceptor Remove the interceptor(s)

func (*SimpleHTTPDef) RoundTrip

func (simpleHTTPSelf *SimpleHTTPDef) RoundTrip(request *http.Request) (*http.Response, error)

RoundTrip Do RoundTrip things(interceptors)

func (*SimpleHTTPDef) SetHTTPClient

func (simpleHTTPSelf *SimpleHTTPDef) SetHTTPClient(client *http.Client)

SetHTTPClient Get the http client and setup interceptors

Jump to

Keyboard shortcuts

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