network

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 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 added in v1.3.4

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 func(pathParam PathParam, body interface{}, target interface{}) *fpgo.MonadIODef

APIHasBody API with request body options

type APIMultipart added in v1.3.4

type APIMultipart func(pathParam PathParam, body *MultipartForm, target interface{}) *fpgo.MonadIODef

APIMultipart API with request body options

type APINoBody

type APINoBody func(pathParam PathParam, target interface{}) *fpgo.MonadIODef

APINoBody API without request body options

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 added in v1.3.4

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 added in v1.3.4

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 {
	TargetObject interface{}
	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

func (*SimpleAPIDef) MakeDelete

func (simpleAPISelf *SimpleAPIDef) MakeDelete(relativeURL string) APINoBody

MakeDelete Make a Delete API

func (*SimpleAPIDef) MakeDoNewRequest

func (simpleAPISelf *SimpleAPIDef) MakeDoNewRequest(method string, relativeURL string) APINoBody

MakeDoNewRequest Make a API without body options

func (*SimpleAPIDef) MakeDoNewRequestWithBodySerializer added in v1.3.4

func (simpleAPISelf *SimpleAPIDef) MakeDoNewRequestWithBodySerializer(method string, relativeURL string, contentType string, bodySerializer BodySerializer) APIHasBody

MakeDoNewRequestWithBodySerializer Make a API with request body options

func (*SimpleAPIDef) MakeDoNewRequestWithMultipartSerializer added in v1.3.4

func (simpleAPISelf *SimpleAPIDef) MakeDoNewRequestWithMultipartSerializer(method string, relativeURL string, multipartSerializer MultipartSerializer) APIMultipart

MakeDoNewRequestWithMultipartSerializer Make a API with request body options

func (*SimpleAPIDef) MakeGet

func (simpleAPISelf *SimpleAPIDef) MakeGet(relativeURL string) APINoBody

MakeGet Make a Get API

func (*SimpleAPIDef) MakePatchJSONBody

func (simpleAPISelf *SimpleAPIDef) MakePatchJSONBody(relativeURL string) APIHasBody

MakePatchJSONBody Make a Patch API with json Body

func (*SimpleAPIDef) MakePatchMultipartBody added in v1.3.4

func (simpleAPISelf *SimpleAPIDef) MakePatchMultipartBody(relativeURL string) APIMultipart

MakePatchMultipartBody Make a Patch API with multipart Body

func (*SimpleAPIDef) MakePostJSONBody

func (simpleAPISelf *SimpleAPIDef) MakePostJSONBody(relativeURL string) APIHasBody

MakePostJSONBody Make a Post API with json Body

func (*SimpleAPIDef) MakePostMultipartBody added in v1.3.4

func (simpleAPISelf *SimpleAPIDef) MakePostMultipartBody(relativeURL string) APIMultipart

MakePostMultipartBody Make a Post API with multipart Body

func (*SimpleAPIDef) MakePutJSONBody

func (simpleAPISelf *SimpleAPIDef) MakePutJSONBody(relativeURL string) APIHasBody

MakePutJSONBody Make a Put API with json Body

func (*SimpleAPIDef) MakePutMultipartBody added in v1.3.4

func (simpleAPISelf *SimpleAPIDef) MakePutMultipartBody(relativeURL string) APIMultipart

MakePutMultipartBody Make a Put API with multipart Body

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 added in v1.3.3

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