utilHttp

package
v0.0.0-...-fe5de01 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 25 Imported by: 3

Documentation

Index

Constants

View Source
const PROXY_TYPE_SOCKS5 = "socks5"

Variables

This section is empty.

Functions

func DownloadFile

func DownloadFile(remoteUrl string, params url.Values, headers map[string]string, timeout ...time.Duration) (body []byte, contentType string, err error)

func GetClientIP

func GetClientIP(r *http.Request) (ip string)

func GetClientIps

func GetClientIps(r *http.Request) (ips []string)

func GetClientPlatform

func GetClientPlatform(r *http.Request) (clientPlatform string)

func GetClientPublicIP

func GetClientPublicIP(r *http.Request) (ip string)

func GetClientSource

func GetClientSource(r *http.Request) (clientSource string)

func Request

func Request(method string, remoteUrl string, params url.Values, headers map[string]string, timeout ...time.Duration) (resp *http.Response, err error)

func RequestJson

func RequestJson(v interface{}, method string, remoteUrl string, params url.Values, headers map[string]string, timeout ...time.Duration) error

func SignCheckRequest

func SignCheckRequest(secret string, r *http.Request, timeValid time.Duration) (err error)

func SignRequestParams

func SignRequestParams(secret string, params url.Values) url.Values

Types

type ApiDataJson

type ApiDataJson struct {
	Status  bool        `json:"status"`
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Errors  []string    `json:"errors"`
	Debug   []string    `json:"debug,omitempty"`
	Data    interface{} `json:"data"`
}

type ApiDataSelectOption

type ApiDataSelectOption struct {
	Key      interface{} `json:"key,omitempty"`
	Label    string      `json:"label,omitempty"`
	Value    interface{} `json:"value,omitempty"`
	Selected bool        `json:"selected,omitempty"`
	Disabled bool        `json:"disabled,omitempty"`
}

type FilteringLogger

type FilteringLogger struct {
	// contains filtered or unexported fields
}

func NewFilteringWriter

func NewFilteringWriter(logger *utilLogger.Logger, excludeStrings ...string) *FilteringLogger

func (FilteringLogger) Write

func (fl FilteringLogger) Write(b []byte) (n int, err error)

type HttpClient

type HttpClient struct {
	// contains filtered or unexported fields
}

func NewHttpClient

func NewHttpClient(baseUrl string, timeout ...time.Duration) (uh *HttpClient)

func (*HttpClient) AddHeader

func (uh *HttpClient) AddHeader(k string, v string) *HttpClient

func (*HttpClient) BasicAuth

func (uh *HttpClient) BasicAuth(user string, password string) *HttpClient

func (*HttpClient) BuildRemoteUrlAndParams

func (uh *HttpClient) BuildRemoteUrlAndParams(method string, path string) (remoteUrl string, params url.Values, err error)

func (*HttpClient) ClearEncryptData

func (uh *HttpClient) ClearEncryptData() *HttpClient

func (*HttpClient) ClearHeader

func (uh *HttpClient) ClearHeader() *HttpClient

func (*HttpClient) ClearParams

func (uh *HttpClient) ClearParams() *HttpClient

func (*HttpClient) ClearRawBody

func (uh *HttpClient) ClearRawBody() *HttpClient

func (*HttpClient) DownloadFile

func (uh *HttpClient) DownloadFile(path string, headers map[string]string) (body []byte, contentType string, err error)

func (*HttpClient) GetAesEncryptor

func (uh *HttpClient) GetAesEncryptor() *utilEnc.AesEncryptor

func (*HttpClient) GetLastRequestParams

func (uh *HttpClient) GetLastRequestParams() url.Values

func (*HttpClient) GetLastRequestUrl

func (uh *HttpClient) GetLastRequestUrl() string

func (*HttpClient) GetLastRespStatusCode

func (uh *HttpClient) GetLastRespStatusCode() int

func (*HttpClient) PostFile

func (uh *HttpClient) PostFile(path string, filedName string, file string, headers map[string]string) (resp *http.Response, err error)

func (*HttpClient) PostFileJson

func (uh *HttpClient) PostFileJson(v interface{}, path string, filedName string, file string, headers map[string]string) error

func (*HttpClient) PostFilePlain

func (uh *HttpClient) PostFilePlain(path string, filedName string, file string, headers map[string]string) (body []byte, err error)

func (*HttpClient) Request

func (uh *HttpClient) Request(method string, path string, additionalHeaders map[string]string) (resp *http.Response, err error)

func (*HttpClient) RequestJson

func (uh *HttpClient) RequestJson(v interface{}, method string, path string, additionalHeaders map[string]string) (err error)

func (*HttpClient) RequestJsonApi

func (uh *HttpClient) RequestJsonApi(v interface{}, method string, path string, additionalHeaders map[string]string) (err error)

func (*HttpClient) RequestJsonApiAndDecode

func (uh *HttpClient) RequestJsonApiAndDecode(v interface{}, method string, path string, additionalHeaders map[string]string) (err error)

func (*HttpClient) RequestPlain

func (uh *HttpClient) RequestPlain(method string, path string, additionalHeaders map[string]string) (body []byte, err error)

func (*HttpClient) SetBaseUrl

func (uh *HttpClient) SetBaseUrl(baseUrl string) *HttpClient

func (*HttpClient) SetClientCertPemContent

func (uh *HttpClient) SetClientCertPemContent(pemContent []byte, key []byte) *HttpClient

func (*HttpClient) SetClientCertPemPath

func (uh *HttpClient) SetClientCertPemPath(path string) *HttpClient

func (*HttpClient) SetLogger

func (uh *HttpClient) SetLogger(logger *utilLogger.Logger) *HttpClient

func (*HttpClient) SetSslVerify

func (uh *HttpClient) SetSslVerify(v bool) *HttpClient

func (*HttpClient) SetTimeout

func (uh *HttpClient) SetTimeout(timeout time.Duration) *HttpClient

func (*HttpClient) SignRequest

func (uh *HttpClient) SignRequest(secret string, method string, path string, params url.Values, additionalHeaders map[string]string) (resp *http.Response, err error)

func (*HttpClient) UseProxySocks5

func (uh *HttpClient) UseProxySocks5(proxyAddr string, proxyUser string, proxyPassword string) *HttpClient

func (*HttpClient) WithAesEncryptor

func (uh *HttpClient) WithAesEncryptor(secret string, appId string) *HttpClient

func (*HttpClient) WithEncryptData

func (uh *HttpClient) WithEncryptData(data map[string]interface{}) *HttpClient

func (*HttpClient) WithJsonData

func (uh *HttpClient) WithJsonData(data interface{}) *HttpClient

func (*HttpClient) WithParams

func (uh *HttpClient) WithParams(params url.Values) *HttpClient

func (*HttpClient) WithRawBody

func (uh *HttpClient) WithRawBody(body string) *HttpClient

type HttpServer

type HttpServer struct {
	// contains filtered or unexported fields
}

func NewHttpServe

func NewHttpServe(handler http.Handler, addresses ...*ServerListenAddr) (s *HttpServer)

func (*HttpServer) Run

func (s *HttpServer) Run(logger *utilLogger.Logger, addresses ...*ServerListenAddr) (err error)

func (*HttpServer) SetIdleTimeout

func (s *HttpServer) SetIdleTimeout(t time.Duration) *HttpServer

func (*HttpServer) SetMaxHeaderBytes

func (s *HttpServer) SetMaxHeaderBytes(i int) *HttpServer

func (*HttpServer) SetReadHeaderTimeout

func (s *HttpServer) SetReadHeaderTimeout(t time.Duration) *HttpServer

func (*HttpServer) SetReadTimeout

func (s *HttpServer) SetReadTimeout(t time.Duration) *HttpServer

func (*HttpServer) SetWriteTimeout

func (s *HttpServer) SetWriteTimeout(t time.Duration) *HttpServer

func (*HttpServer) VerifyClientSsl

func (s *HttpServer) VerifyClientSsl(caFile string) *HttpServer

type Paginator

type Paginator struct {
	Request     *http.Request `json:"-"`
	PerPage     int           `json:"per_page"`
	CurrentPage int           `json:"current_page"`
	MaxPages    int           `json:"-"`

	Total     int64 `json:"total"`
	PageRange []int `json:"page_range"`
	PageNums  int   `json:"page_nums"`
}

func NewPaginator

func NewPaginator(req *http.Request, pageSize int, total interface{}) *Paginator

func (*Paginator) GetCurrentPage

func (p *Paginator) GetCurrentPage() int

func (*Paginator) GetPageNums

func (p *Paginator) GetPageNums() int

func (*Paginator) GetPages

func (p *Paginator) GetPages() []int

func (*Paginator) GetTotal

func (p *Paginator) GetTotal() int64

func (*Paginator) HasNext

func (p *Paginator) HasNext() bool

func (*Paginator) HasPages

func (p *Paginator) HasPages() bool

func (*Paginator) HasPrev

func (p *Paginator) HasPrev() bool

func (*Paginator) IsActive

func (p *Paginator) IsActive(page int) bool

func (*Paginator) Offset

func (p *Paginator) Offset() int
func (p *Paginator) PageLink(page int) string

func (*Paginator) PageLinkFirst

func (p *Paginator) PageLinkFirst() (link string)

func (*Paginator) PageLinkLast

func (p *Paginator) PageLinkLast() (link string)

func (*Paginator) PageLinkNext

func (p *Paginator) PageLinkNext() (link string)

func (*Paginator) PageLinkPrev

func (p *Paginator) PageLinkPrev() (link string)

func (*Paginator) SetTotal

func (p *Paginator) SetTotal(total interface{})

type ServerListenAddr

type ServerListenAddr struct {
	Network           string `json:"network,omitempty"`
	Addr              string `json:"addr,omitempty"`
	Uid               int    `json:"uid,omitempty"`
	Gid               int    `json:"gid,omitempty"`
	SslServerCertFile string `json:"ssl_server_cert_file,omitempty"`
	SslServerKeyFile  string `json:"ssl_server_key_file,omitempty"`
}

Jump to

Keyboard shortcuts

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