Back to godoc.org

Package client

v0.1.11
Latest Go to latest

The latest major version is .

Published: Sep 22, 2020 | License: MIT | Module: gitee.com/zakums06/go-scaffold

Index

Variables

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

ErrBadRequest for request data error

func GetExternalIP

func GetExternalIP() (string, error)

GetExternalIP TLDR

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

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier