client

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadRequest = errors.New("bad request")

ErrBadRequest for request data error

Functions

func GetExternalIP

func GetExternalIP() (string, error)

GetExternalIP TL;DR

Types

type BaseAPI

type BaseAPI struct {
	Host string
	// global header will send in each request
	Headers map[string]string
	// URLPrefix after host:port
	URLPrefix        string
	RetryCount       int
	RetrySleepSecond int
}

BaseAPI for api client

func (*BaseAPI) Delete

func (s *BaseAPI) Delete(uri string, params map[string]string, headers map[string]string, data interface{}) (*Response, error)

Delete request

func (*BaseAPI) Get

func (s *BaseAPI) Get(uri string, params map[string]string, headers map[string]string) (*Response, error)

Get request

func (*BaseAPI) Post

func (s *BaseAPI) Post(uri string, params map[string]string, headers map[string]string, data interface{}) (*Response, error)

Post request

func (*BaseAPI) Put

func (s *BaseAPI) Put(uri string, params map[string]string, headers map[string]string, data interface{}) (*Response, error)

Put request

func (*BaseAPI) Request

func (s *BaseAPI) Request(req *RequestForm) (*Response, error)

Request send to remote host request form contains: method in [GET POST DELETE PUT] url or uri params = query parameter data = post data headers

func (*BaseAPI) RequestWithRetry

func (s *BaseAPI) RequestWithRetry(r *RequestForm) (*Response, error)

RequestWithRetry do

type RequestForm

type RequestForm struct {
	URL     string            `form:"url" json:"url"`
	URI     string            `form:"uri" json:"uri"`
	Method  string            `form:"method" json:"method"`
	Params  map[string]string `form:"params" json:"params"`
	Data    interface{}       `form:"data" json:"data"`
	Headers map[string]string `form:"headers" json:"headers"`
}

RequestForm for package request data

type Response

type Response struct {
	Content []byte
	Status  int
}

Response for package response body

func (*Response) ToJSON

func (r *Response) ToJSON() map[string]interface{}

ToJSON format response content to map

Jump to

Keyboard shortcuts

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