Documentation ¶
Index ¶
- Constants
- Variables
- func BindAndValidate(c echo.Context, i interface{}) error
- func GetRealIp(req *http.Request) string
- func HttpGet(url string, timeout int) (*http.Response, error)
- func HttpGetBody(url string, timeout int) (*http.Response, []byte, error)
- func HttpPost(url string, body interface{}, timeout int) (*http.Response, error)
- func HttpPostBody(url string, body interface{}, timeout int) (*http.Response, []byte, error)
- func IsConnError(err error) bool
- func NewProxyTransport(proxyHost string, proxyPort int, isHttp bool) (*http.Transport, error)
- func QueryMustParam(c echo.Context, key string) (string, error)
- func QueryOptionalParam(c echo.Context, key string) (string, bool)
- func RegisterHandle(...)
- func ResponseToMap(body []byte) (map[string]interface{}, error)
- func ResultResp(status, code int, result interface{}) error
- func SendResp(c echo.Context, resp error) error
- func StatusResp(status int) error
- func SuccessResp(result interface{}) error
- func ValidateMust(input interface{}, keys ...string) error
- func Wrap(err error) error
- type ApiGateway
- type AuthJsonClient
- func (c *AuthJsonClient) DelR(url string, headers map[string]string) (*resty.Response, error)
- func (c *AuthJsonClient) Get(url string, headers map[string]string) (typex.JsonMap, error)
- func (c *AuthJsonClient) Login(method, url string, headers map[string]string, data interface{}, ...) (string, error)
- func (c *AuthJsonClient) Post(url string, headers map[string]string, data interface{}) (typex.JsonMap, error)
- func (c *AuthJsonClient) Put(url string, headers map[string]string, data interface{}) (typex.JsonMap, error)
- func (c *AuthJsonClient) Request(method, url string, headers map[string]string, data interface{}) (typex.JsonMap, error)
- func (c *AuthJsonClient) RequestR(result interface{}, method, url string, headers map[string]string, ...) (*resty.Response, error)
- type BindUnmarshaler
- type Binder
- type DefaultBinder
- type DropWriter
- type HttpClient
- type JsonClient
- func (c *JsonClient) Client() *resty.Client
- func (c *JsonClient) Del(url string, headers map[string]string, data interface{}) (typex.JsonMap, error)
- func (c *JsonClient) DelR(url string, headers map[string]string) (*resty.Response, error)
- func (c *JsonClient) Get(url string, headers map[string]string) (typex.JsonMap, error)
- func (c *JsonClient) GetR(url string, headers map[string]string) (*resty.Response, error)
- func (c *JsonClient) Post(url string, headers map[string]string, data interface{}) (typex.JsonMap, error)
- func (c *JsonClient) PostR(url string, headers map[string]string, data interface{}) (*resty.Response, error)
- func (c *JsonClient) Put(url string, headers map[string]string, data interface{}) (typex.JsonMap, error)
- func (c *JsonClient) PutR(url string, headers map[string]string, data interface{}) (*resty.Response, error)
- func (c *JsonClient) Request(method, url string, headers map[string]string, data interface{}) (typex.JsonMap, error)
- func (c *JsonClient) RequestR(result interface{}, method, url string, headers map[string]string, ...) (*resty.Response, error)
- func (c *JsonClient) RequestTimeout(method, url string, headers map[string]string, data interface{}, timeout int) (typex.JsonMap, error)
- func (c *JsonClient) SetInsecure()
- func (c *JsonClient) SetReuseConnection()
- func (c *JsonClient) SetStatsChan(ch chan<- *RequestStats)
- func (c *JsonClient) SetTransport(maxIdleConns, maxIdleConnsPerHost int)
- func (c *JsonClient) StatusError(method, url string, rsp *resty.Response) *StatusError
- func (c *JsonClient) Transport() http.RoundTripper
- func (c *JsonClient) Url(api string) string
- type JsonResponse
- type LogConfig
- type RequestStats
- type RoundrobinClient
- func (c *RoundrobinClient) Client() *JsonClient
- func (c *RoundrobinClient) DelR(url string, headers map[string]string) (*resty.Response, error)
- func (c *RoundrobinClient) Get(url string, headers map[string]string) (typex.JsonMap, error)
- func (c *RoundrobinClient) GetR(url string, headers map[string]string) (*resty.Response, error)
- func (c *RoundrobinClient) Post(url string, headers map[string]string, data interface{}) (typex.JsonMap, error)
- func (c *RoundrobinClient) PostR(url string, headers map[string]string, data interface{}) (*resty.Response, error)
- func (c *RoundrobinClient) Put(url string, headers map[string]string, data interface{}) (typex.JsonMap, error)
- func (c *RoundrobinClient) PutR(url string, headers map[string]string, data interface{}) (*resty.Response, error)
- func (c *RoundrobinClient) Request(method, url string, headers map[string]string, data interface{}) (typex.JsonMap, error)
- func (c *RoundrobinClient) RequestR(result interface{}, method, url string, headers map[string]string, ...) (*resty.Response, error)
- func (c *RoundrobinClient) SetInsecure()
- func (c *RoundrobinClient) SetReuseConnection()
- func (c *RoundrobinClient) SetTransport(maxIdleConns, maxIdleConnsPerHost int)
- func (c *RoundrobinClient) StatusError(method, api string, rsp *resty.Response) *StatusError
- func (c *RoundrobinClient) Url(api string) string
- type RrServer
- type Stats
- type StatusError
Constants ¶
View Source
const ( ERR_NONE = "none" ERR_CONNTION = "Connection Error" ERR_READ = "Read Content Error" ERR_REQ = "Request Error" ERR_JSON = "Encode/Decode jsonx Error" )
View Source
const (
DefaultB0dyBufferSize = 2000
)
Variables ¶
View Source
var ( TagHttpX = "hx_tag" TagFiledPlace = "hx_place" TagFieldName = "hx_query_name" TagFieldMust = "hx_must" TagFieldDefault = "hx_default" TagFieldRange = "hx_range" )
View Source
var ( NewHTTPError = echo.NewHTTPError MIMEApplicationForm = echo.MIMEApplicationForm HeaderContentType = echo.HeaderContentType MIMEApplicationJSON = echo.MIMEApplicationJSON MIMETextXML = echo.MIMETextXML MIMEApplicationXML = echo.MIMEApplicationXML MIMEMultipartForm = echo.MIMEMultipartForm ErrUnsupportedMediaType = echo.ErrUnsupportedMediaType )
View Source
var ErrBadParams error = errors.New("Bad input params")
View Source
var StatsTotalReqs int64
View Source
var UserAgent string = "Json Http Client"
var ErrNot200OK error = errors.New("the response is not 200 OK")
Functions ¶
func BindAndValidate ¶
func HttpPostBody ¶
func IsConnError ¶
func NewProxyTransport ¶
func RegisterHandle ¶
func ResponseToMap ¶
func ResultResp ¶
func StatusResp ¶
func SuccessResp ¶
func SuccessResp(result interface{}) error
func ValidateMust ¶
Types ¶
type ApiGateway ¶
type ApiGateway struct { Ctx context.Context Echo *echo.Echo Logger *logrus.Logger LogConf *LogConfig LogFormat logrus.Formatter }
func NewApiGateway ¶
func (*ApiGateway) RoutesToString ¶
func (agw *ApiGateway) RoutesToString() string
func (*ApiGateway) Run ¶
func (agw *ApiGateway) Run(ip, port string) error
func (*ApiGateway) Stop ¶
func (agw *ApiGateway) Stop() error
type AuthJsonClient ¶
type AuthJsonClient struct { Client JsonClient // contains filtered or unexported fields }
type BindUnmarshaler ¶
type BindUnmarshaler interface { // UnmarshalParam decodes and assigns a value from an form or query param. UnmarshalParam(param string) error }
BindUnmarshaler is the interface used to wrap the UnmarshalParam method.
type DefaultBinder ¶
type DefaultBinder struct{}
DefaultBinder is the default implementation of the Binder interface.
type DropWriter ¶
type DropWriter struct { }
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
func NewHttpClient ¶
func NewHttpClient(transport http.RoundTripper) *HttpClient
func NewProxyClient ¶
func NewProxyClient(proxyHost string, proxyPort int, isHttp bool) (*HttpClient, error)
func (*HttpClient) GetAndDrop ¶
func (pc *HttpClient) GetAndDrop(url string) (*Stats, error)
type JsonClient ¶
type JsonClient struct { IsHttps bool Host string Port int Timeout int // in milliseconds // contains filtered or unexported fields }
func NewJsonClient ¶
func NewJsonClient(host string, port int, timeout int) *JsonClient
func NewJsonClientWithRetry ¶
func NewJsonClientWithRetry(host string, port, timeout, retryCount, retryWaitTime int) *JsonClient
func (*JsonClient) Client ¶
func (c *JsonClient) Client() *resty.Client
func (*JsonClient) RequestTimeout ¶
func (*JsonClient) SetInsecure ¶
func (c *JsonClient) SetInsecure()
func (*JsonClient) SetReuseConnection ¶
func (c *JsonClient) SetReuseConnection()
func (*JsonClient) SetStatsChan ¶
func (c *JsonClient) SetStatsChan(ch chan<- *RequestStats)
func (*JsonClient) SetTransport ¶
func (c *JsonClient) SetTransport(maxIdleConns, maxIdleConnsPerHost int)
func (*JsonClient) StatusError ¶
func (c *JsonClient) StatusError(method, url string, rsp *resty.Response) *StatusError
func (*JsonClient) Transport ¶
func (c *JsonClient) Transport() http.RoundTripper
func (*JsonClient) Url ¶
func (c *JsonClient) Url(api string) string
type JsonResponse ¶
type JsonResponse struct { RequestId *string `jsonx:"RequestId,omitempty"` Status int `jsonx:"-"` Code *string `jsonx:"Code,omitempty"` CodeInt *int `jsonx:"CodeInt,omitempty"` Message *string `jsonx:"Message,omitempty"` Result any `jsonx:"Result,omitempty"` // contains filtered or unexported fields }
func ErrStrResp ¶
func ErrStrResp(status, code int, msg string) *JsonResponse
func ErrorResp ¶
func ErrorResp(status, code int, err error) *JsonResponse
func (*JsonResponse) Error ¶
func (e *JsonResponse) Error() string
func (*JsonResponse) IsNoContent ¶
func (e *JsonResponse) IsNoContent() bool
func (*JsonResponse) ToString ¶
func (e *JsonResponse) ToString() string
func (*JsonResponse) Unwrap ¶
func (e *JsonResponse) Unwrap() error
type LogConfig ¶
type LogConfig struct { FileConfig log.FileConfig Level string BodyBufferSize int `vx_default:"2000"` }
type RequestStats ¶
type RequestStats struct { Scheme string Host string Port int Uri string Method string ReqTime time.Time SendTime time.Time RspTime time.Time Latency int64 PreTime int64 Status int }
format := "${time_rfc3339} ${time_unix} ${status} ${method} ${latency} ${remote_ip} ${bytes_in} ${bytes_out} ${uri}\n"
func (*RequestStats) LogLine ¶
func (s *RequestStats) LogLine() string
type RoundrobinClient ¶
type RoundrobinClient struct {
// contains filtered or unexported fields
}
func NewRoundrobinClient ¶
func NewRoundrobinClient2 ¶
func NewRoundrobinClient2(service string, cl []*JsonClient, sign *auth.SignCfg, retryTime int) *RoundrobinClient
func (*RoundrobinClient) Client ¶
func (c *RoundrobinClient) Client() *JsonClient
func (*RoundrobinClient) RequestR ¶
func (c *RoundrobinClient) RequestR(result interface{}, method, url string, headers map[string]string, data interface{}) (*resty.Response, error)
light wrapper of RoundrobinClient.RequestR
func (*RoundrobinClient) SetInsecure ¶
func (c *RoundrobinClient) SetInsecure()
func (*RoundrobinClient) SetReuseConnection ¶
func (c *RoundrobinClient) SetReuseConnection()
must called before any request
func (*RoundrobinClient) SetTransport ¶
func (c *RoundrobinClient) SetTransport(maxIdleConns, maxIdleConnsPerHost int)
must called before any request
func (*RoundrobinClient) StatusError ¶
func (c *RoundrobinClient) StatusError(method, api string, rsp *resty.Response) *StatusError
func (*RoundrobinClient) Url ¶
func (c *RoundrobinClient) Url(api string) string
type Stats ¶
type StatusError ¶
func NewStatusError ¶
func NewStatusError(method, host, api string, rsp *resty.Response) *StatusError
func NewStatusError2 ¶
func NewStatusError2(method, url string, rsp *resty.Response) *StatusError
func (*StatusError) Body ¶
func (e *StatusError) Body() string
func (*StatusError) Error ¶
func (e *StatusError) Error() string
Click to show internal directories.
Click to hide internal directories.