client

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const DownloadKey = ".downloading"
View Source
const (
	UserAgent1 = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
)

Variables

This section is empty.

Functions

func DefaultLogger

func DefaultLogger(url, method, auth string, reqBody, respBody *Body, status int, process time.Duration, err error)

func DisableLog

func DisableLog()

func Download

func Download(filepath string, reader io.Reader) error

func DownloadFile

func DownloadFile(filepath, url string) error

func DownloadFileWithRefer

func DownloadFileWithRefer(filepath, url, refer string) error

func DownloadFileWithReq

func DownloadFileWithReq(filepath, url string, setReq Option) error

func DownloadIfNotExists

func DownloadIfNotExists(filepath string, reader io.Reader) error

func DownloadImage

func DownloadImage(filepath, url string) error

func GetFile

func GetFile(url string) (io.ReadCloser, error)

func GetFileWithRefer

func GetFileWithRefer(url, refer string) (io.ReadCloser, error)

func GetFileWithReq

func GetFileWithReq(url string, setReq Option) (io.ReadCloser, error)

func GetImage

func GetImage(url string) (io.ReadCloser, error)

func GetRandUserAgent

func GetRandUserAgent() string

func ImageOption

func ImageOption(req *http.Request)

func NewReplaceHttpRequest

func NewReplaceHttpRequest(r *http.Request) *replaceHttpRequest

func ReplaceHttpRequest

func ReplaceHttpRequest(r *http.Request, url, method string, body io.ReadCloser) *http.Request

func SetClient

func SetClient(client *http.Client)

func SetDefaultLogger

func SetDefaultLogger(logger LogCallback)

func SetTimeout

func SetTimeout(timeout time.Duration)

func SimpleDelete

func SimpleDelete(url string, param, response interface{}) error

func SimpleGet

func SimpleGet(url string, response any) error

func SimpleGetStream

func SimpleGetStream(url string) (io.ReadCloser, error)

func SimplePost

func SimplePost(url string, param, response interface{}) error

func SimplePut

func SimplePut(url string, param, response interface{}) error

func UrlParam

func UrlParam(param interface{}) string

Types

type Body

type Body struct {
	Data        []byte
	ContentType ContentType
}

func NewBody

func NewBody(data []byte, contentType ContentType) *Body

func (*Body) IsJson

func (b *Body) IsJson() bool

func (*Body) IsProtobuf

func (b *Body) IsProtobuf() bool

type Config

type Config struct {
}

type ContentType

type ContentType uint8
const (
	ContentTypeJson ContentType = iota
	ContentTypeForm
	ContentTypeFormData
	ContentTypeProtobuf
	ContentTypeText
	ContentTypeImage
)
type Header []string

func NewHeader

func NewHeader() *Header

func (*Header) Add

func (h *Header) Add(k, v string) *Header

type LogCallback

type LogCallback func(url, method, auth string, reqBody, respBody *Body, status int, process time.Duration, err error)

type Logger

type Logger interface {
	SetPrefix(string)
	Printf(format string, v ...interface{})
	Println(v ...interface{})
}

type Option

type Option func(req *http.Request)

func SetAccept

func SetAccept(refer string) Option

func SetRefer

func SetRefer(refer string) Option

type Pair

type Pair struct {
	K, V string
}

type RawResponse

type RawResponse = []byte

type Request

type Request struct {
	AuthUser, AuthPass string
	// contains filtered or unexported fields
}

Request ...

func New

func New(url string) *Request

func NewDeleteRequest

func NewDeleteRequest(url string) *Request

func NewGetRequest

func NewGetRequest(url string) *Request

func NewPostRequest

func NewPostRequest(url string) *Request

func NewPutRequest

func NewPutRequest(url string) *Request

func NewRequest

func NewRequest(url, method string) *Request

func (*Request) AbleLog

func (req *Request) AbleLog() *Request

func (*Request) AddHeader

func (req *Request) AddHeader(k, v string) *Request

func (*Request) CacheDelete

func (req *Request) CacheDelete(url string, param, response interface{}) error

func (*Request) CacheDo

func (req *Request) CacheDo(url, method string, param, response interface{}) error

func (*Request) CacheGet

func (req *Request) CacheGet(url string, response interface{}) error

func (*Request) CachePost

func (req *Request) CachePost(url string, param, response interface{}) error

func (*Request) CachePut

func (req *Request) CachePut(url string, param, response interface{}) error

func (*Request) CachedHeader

func (req *Request) CachedHeader(key string) *Request

func (*Request) CompleteDo

func (req *Request) CompleteDo(url, method string, param, response interface{}) error

func (*Request) ContentType

func (req *Request) ContentType(contentType ContentType) *Request

func (*Request) Delete

func (req *Request) Delete(url string, param, response interface{}) error

func (*Request) DisableLog

func (req *Request) DisableLog() *Request

func (*Request) Do

func (req *Request) Do(param, response interface{}) error

Do create a HTTP request

func (*Request) DoEmpty

func (req *Request) DoEmpty() error

func (*Request) DoRaw

func (req *Request) DoRaw(param interface{}) (RawResponse, error)

func (*Request) DoStream

func (req *Request) DoStream(param interface{}) (io.ReadCloser, error)

func (*Request) DoWithNoParam

func (req *Request) DoWithNoParam(response interface{}) error

func (*Request) DoWithNoResponse

func (req *Request) DoWithNoResponse(param interface{}) error

func (*Request) Download

func (req *Request) Download(url, path string) error

func (*Request) Get

func (req *Request) Get(url string, response interface{}) error

func (*Request) Method

func (req *Request) Method(method string) *Request

func (*Request) Post

func (req *Request) Post(url string, param, response interface{}) error

func (*Request) Put

func (req *Request) Put(url string, param, response interface{}) error

func (*Request) ResponseHandler

func (req *Request) ResponseHandler(handler func([]byte) ([]byte, error)) *Request

func (*Request) RetryHandle

func (req *Request) RetryHandle(handle func(*Request)) *Request

func (*Request) RetryTimes

func (req *Request) RetryTimes(retryTimes int) *Request

func (*Request) SetHeader

func (req *Request) SetHeader(header Header) *Request

func (*Request) Timeout

func (req *Request) Timeout(timeout time.Duration) *Request

func (*Request) Url

func (req *Request) Url(url string) *Request

func (*Request) UrlParam

func (req *Request) UrlParam(param interface{}) *Request

func (*Request) WithClient

func (req *Request) WithClient(client *http.Client) *Request

func (*Request) WithLogger

func (req *Request) WithLogger(logger LogCallback) *Request

type ResponseBody

type ResponseBody struct {
	Status  int         `json:"status"`
	Data    interface{} `json:"data"`
	Message string      `json:"message"`
}

func (*ResponseBody) CheckError

func (res *ResponseBody) CheckError() error

type ResponseBodyCheck

type ResponseBodyCheck interface {
	CheckError() error
}

func CommonResponse

func CommonResponse(response interface{}) ResponseBodyCheck

type SetParams

type SetParams func(req *Request) *Request

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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