gohttpx

package
v1.2.175 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

gohttpx 模块

  • 快捷使用http 请求
resp, err := gohttpx.PostJson(Email.Api, data)
if err != nil {
    logx.Error("邮件发送失败:" + string(data) + ",error:" + err.Error())
    return err
} else {
    logx.Infof("executeSendEmail result:%s data:%s", string(resp), string(data))
}
return nil
rst, err := gohttpx.Post(url, []byte(postParams))
clientIp := gohttpx.GetClientIp(request)

Documentation

Index

Constants

View Source
const (
	TAG = "gohttp"

	CONTENT_TYPE_XML  = "application/xml"
	CONTENT_TYPE_JSON = "application/json"
	CONTENT_TYPE_FORM = "application/x-www-form-urlencoded"
)

Variables

This section is empty.

Functions

func Get

func Get(url string) ([]byte, error)

func GetClientIp

func GetClientIp(r *http.Request) string

GetClientIp returns the client ip of this request without port. Note that this ip address might be modified by client header.

func GetWithQuery

func GetWithQuery(url string, data []byte) ([]byte, error)

func Post

func Post(url string, data []byte) ([]byte, error)

func PostJson

func PostJson(url string, data []byte) ([]byte, error)

func Put

func Put(url string, data []byte) ([]byte, error)

func Upload

func Upload(url, fileField, fileName string, fh io.Reader, data map[string]string) (b []byte, err error)

Types

type Option

type Option struct {
	Name  string
	Value interface{}
}

func ContentTypeFormOption

func ContentTypeFormOption() Option

func ContentTypeJsonOption

func ContentTypeJsonOption() Option

func ContentTypeXmlOption

func ContentTypeXmlOption() Option

func DebugOption

func DebugOption() Option

func HeaderOption

func HeaderOption(field, value string) Option

func TlsOption

func TlsOption(caCrtFile, clientCrtFile, clientKeyFile string) Option

type Request

type Request struct {
	Headers map[string]string
	Tls     *Tls
	// contains filtered or unexported fields
}

func Debug

func Debug() *Request

func New

func New(opts ...Option) *Request

func SetHeader

func SetHeader(name, value string) *Request

func (*Request) Debug

func (r *Request) Debug() *Request

func (*Request) Do

func (r *Request) Do(method, url string, reader io.Reader) (rst []byte, err error)

func (*Request) Get

func (r *Request) Get(url string) ([]byte, error)

func (*Request) GetWithQuery

func (r *Request) GetWithQuery(url string, data []byte) ([]byte, error)

func (*Request) JsonContentType

func (r *Request) JsonContentType() *Request

func (*Request) Post

func (r *Request) Post(url string, data []byte) ([]byte, error)

func (*Request) PostJson

func (r *Request) PostJson(url string, data []byte) ([]byte, error)

func (*Request) Put

func (r *Request) Put(url string, data []byte) ([]byte, error)

func (*Request) SetContentType

func (r *Request) SetContentType(contentType string) *Request

func (*Request) SetHeader

func (r *Request) SetHeader(name, value string) *Request

func (*Request) SetTimeout

func (r *Request) SetTimeout(d time.Duration) *Request

func (*Request) Upload

func (r *Request) Upload(url, fileField, fileName string, fh io.Reader, data map[string]string) ([]byte, error)

type Tls

type Tls struct {
	CaCrtFile     string
	ClientCrtFile string
	ClientKeyFile string
}

func (*Tls) CaCrt

func (s *Tls) CaCrt() []byte

func (*Tls) ClientCrt

func (s *Tls) ClientCrt() tls.Certificate

Jump to

Keyboard shortcuts

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