Documentation
¶
Overview ¶
Package httplib is used as http.Client Usage:
import "github.com/astaxie/beego/httplib"
b := httplib.Post("http://beego.me/") b.Param("username","astaxie") b.Param("password","123456") b.PostFile("uploadfile1", "httplib.pdf") b.PostFile("uploadfile2", "httplib.txt") str, err := b.String() if err != nil { t.Fatal(err) } fmt.Println(str) more docs http://beego.me/docs/module/httplib.md
Index ¶
- func BToI(b bool) int
- func ByteToStr(b []byte) string
- func CreateMsPath(args ...interface{}) error
- func EncodeGetUrlParam(urlOrigin string) (string, string, error)
- func EncodeGetUrlParamValues(urlParams url.Values) string
- func EscapeQueryParam(query string) string
- func FilterComment(originStr, startStr, endStr string) string
- func GetDateByStampAndReduceDate(stamp int64, format string, date ...int) string
- func GetDateByStampAndReduceDateUTC(stamp int64, format string, date ...int) string
- func GetDateByTimeStamp(timeStamp int64) string
- func GetDateByTimeStampAndFormat(timeStamp int64, format string) string
- func GetDateByTimeStampAndFormatUTC(timeStamp int64, format string) string
- func GetDateByTimeStampUTC(timeStamp int64) string
- func GetFloatRandom32(interval int) float32
- func GetFloatRandom64(interval int) float64
- func GetIntRandom(interval int) int
- func GetNowDate() string
- func GetNowDateByFormat(format string) string
- func GetNowDateByFormatUTC(format string) string
- func GetNowDateUTC() string
- func GetNowTimeStamp() int64
- func GetStampByDateAndFormat(date string, format string) int64
- func GetStartPos(page int, size int) int
- func IToB(i int) bool
- func InSlice(v string, sl []string) bool
- func NewReportError(err error) error
- func PathExists(path string) (bool, error)
- func Prepend(sc *[]interface{}, value ...interface{}) *[]interface{}
- func PrintJsonIndent(data interface{})
- func ReadFile(params ...interface{}) string
- func ReadFileToByte(params ...interface{}) []byte
- func SendEmail(subject string, message string)
- func SetDefaultSetting(setting BeegoHTTPSettings)
- func StrToByte(s string) []byte
- func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)
- func WriteDataToFile(path string, params ...interface{}) (err error)
- type BeegoHTTPRequest
- func (b *BeegoHTTPRequest) Body(data interface{}) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) Bytes() ([]byte, error)
- func (b *BeegoHTTPRequest) Debug(isdebug bool) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) DoRequest() (resp *http.Response, err error)
- func (b *BeegoHTTPRequest) DumpBody(isdump bool) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) DumpRequest() []byte
- func (b *BeegoHTTPRequest) GetRequest() *http.Request
- func (b *BeegoHTTPRequest) Header(key, value string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) JSONBody(obj interface{}) (*BeegoHTTPRequest, error)
- func (b *BeegoHTTPRequest) Param(key, value string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) PostFile(formname, filename string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) Response() (*http.Response, error)
- func (b *BeegoHTTPRequest) Retries(times int) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetBasicAuth(username, password string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetCookie(cookie *http.Cookie) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetEnableCookie(enable bool) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetHost(host string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetProtocolVersion(vers string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetTLSClientConfig(config *tls.Config) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetTransport(transport http.RoundTripper) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetUserAgent(useragent string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) Setting(setting BeegoHTTPSettings) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) String() (string, error)
- func (b *BeegoHTTPRequest) ToFile(filename string) error
- func (b *BeegoHTTPRequest) ToJSON(v interface{}) error
- func (b *BeegoHTTPRequest) ToXML(v interface{}) error
- func (b *BeegoHTTPRequest) ToYAML(v interface{}) error
- func (b *BeegoHTTPRequest) XMLBody(obj interface{}) (*BeegoHTTPRequest, error)
- func (b *BeegoHTTPRequest) YAMLBody(obj interface{}) (*BeegoHTTPRequest, error)
- type BeegoHTTPSettings
- type JsonToMapValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateMsPath ¶
func CreateMsPath(args ...interface{}) error
The second param (bool) This param is used to let you choose whether create Multistage path. example: If you given path which called "./files/test/test.txt", and "./files" or "./files/test" is not exists, the program will first create them.
The third param (bool) If you want to create a directory Please given the third param, example: CreateMsPath("test", true, true)
func EncodeGetUrlParam ¶
* This method can encode the url query params. If the params have some special character This encode method maybe will return a error result, please check your params and use with caution. return string, error
func EncodeGetUrlParamValues ¶
* This method can encode the url query params. urlParams example:
urlParams := url.Values{} urlParams.Add("key", "value") query := EncodeGetUrlParamValues(urlParams)
return string
func EscapeQueryParam ¶
func FilterComment ¶
过滤给定字符串(这个函数的目的开始是为了过滤我的json配置文件里的自定义注释)里的 注释,根据输入的 注释开头 和 结尾进行过滤 过滤的 开头和结尾需要转义特殊字符, 具体方式看例子 example:
FilterComment(data, "/\\*", "\\*/")
func GetDateByStampAndReduceDate ¶
根据时间戳和给定格式以及 要加(减)的 年 月 日 获取对应时间字符串
func GetDateByTimeStamp ¶
根据时间戳获取 日期 返回一个字符串 According to the time stamp, get a date string. format is 2006-01-02 15:04:05
func GetDateByTimeStampAndFormat ¶
根据时间戳和想要的时间格式进行获取时间
func GetDateByTimeStampAndFormatUTC ¶
根据时间戳和想要的时间格式进行获取时间
func GetDateByTimeStampUTC ¶
根据时间戳获取 日期 返回一个字符串 According to the time stamp, get a date string. format is 2006-01-02 15:04:05
func GetFloatRandom32 ¶
func GetFloatRandom64 ¶
func GetIntRandom ¶
func GetStampByDateAndFormat ¶
根据日期获取时间戳
func GetStartPos ¶
根据页码和 每页大小获取 对应的开始位置(用以sql的offset 或者 limit)
func NewReportError ¶
* 用于报告错误行数和文件名在哪里,便于找bug This func is used to report the error line and file name so that we can find bug quickly.
一般在项目中应用的时候,应该配置一个全局的控制变量,并且打开注释代码块里的注释, 根据你的全局变量进行修改,以达到可以关闭的效果,否则是默认都会报告的
func PathExists ¶
func PrintJsonIndent ¶
func PrintJsonIndent(data interface{})
* 用来打印json字符串,方便进行观察 由于只是工具函数,调试开发用,所以不需要考虑资源消耗问题,直接上interface
func ReadFile ¶
func ReadFile(params ...interface{}) string
* 读取文件, buffer方式,可以读大文件 param 1: file path param 2: buffer size
func ReadFileToByte ¶
func ReadFileToByte(params ...interface{}) []byte
* 读取文件, buffer方式,可以读大文件 param 1: file path param 2: buffer size
func SetDefaultSetting ¶
func SetDefaultSetting(setting BeegoHTTPSettings)
SetDefaultSetting Overwrite default settings
func TimeoutDialer ¶
func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)
TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.
func WriteDataToFile ¶
写内容到文件 params: you can give any type unlimit number data Write content to a file. If there is not exists, the method will auto create it.
Types ¶
type BeegoHTTPRequest ¶
type BeegoHTTPRequest struct {
// contains filtered or unexported fields
}
BeegoHTTPRequest provides more useful methods for requesting one url than http.Request.
func Delete ¶
func Delete(url string) *BeegoHTTPRequest
Delete returns *BeegoHttpRequest DELETE method.
func Head ¶
func Head(url string) *BeegoHTTPRequest
Head returns *BeegoHttpRequest with HEAD method.
func NewBeegoRequest ¶
func NewBeegoRequest(rawurl, method string) *BeegoHTTPRequest
NewBeegoRequest return *BeegoHttpRequest with specific method
func Post ¶
func Post(url string) *BeegoHTTPRequest
Post returns *BeegoHttpRequest with POST method.
func (*BeegoHTTPRequest) Body ¶
func (b *BeegoHTTPRequest) Body(data interface{}) *BeegoHTTPRequest
Body adds request raw body. it supports string and []byte.
func (*BeegoHTTPRequest) Bytes ¶
func (b *BeegoHTTPRequest) Bytes() ([]byte, error)
Bytes returns the body []byte in response. it calls Response inner.
func (*BeegoHTTPRequest) Debug ¶
func (b *BeegoHTTPRequest) Debug(isdebug bool) *BeegoHTTPRequest
Debug sets show debug or not when executing request.
func (*BeegoHTTPRequest) DoRequest ¶
func (b *BeegoHTTPRequest) DoRequest() (resp *http.Response, err error)
DoRequest will do the client.Do
func (*BeegoHTTPRequest) DumpBody ¶
func (b *BeegoHTTPRequest) DumpBody(isdump bool) *BeegoHTTPRequest
DumpBody setting whether need to Dump the Body.
func (*BeegoHTTPRequest) DumpRequest ¶
func (b *BeegoHTTPRequest) DumpRequest() []byte
DumpRequest return the DumpRequest
func (*BeegoHTTPRequest) GetRequest ¶
func (b *BeegoHTTPRequest) GetRequest() *http.Request
GetRequest return the request object
func (*BeegoHTTPRequest) Header ¶
func (b *BeegoHTTPRequest) Header(key, value string) *BeegoHTTPRequest
Header add header item string in request.
func (*BeegoHTTPRequest) JSONBody ¶
func (b *BeegoHTTPRequest) JSONBody(obj interface{}) (*BeegoHTTPRequest, error)
JSONBody adds request raw body encoding by JSON.
func (*BeegoHTTPRequest) Param ¶
func (b *BeegoHTTPRequest) Param(key, value string) *BeegoHTTPRequest
Param adds query param in to request. params build query string as ?key1=value1&key2=value2...
func (*BeegoHTTPRequest) PostFile ¶
func (b *BeegoHTTPRequest) PostFile(formname, filename string) *BeegoHTTPRequest
PostFile add a post file to the request
func (*BeegoHTTPRequest) Response ¶
func (b *BeegoHTTPRequest) Response() (*http.Response, error)
Response executes request client gets response mannually.
func (*BeegoHTTPRequest) Retries ¶
func (b *BeegoHTTPRequest) Retries(times int) *BeegoHTTPRequest
Retries sets Retries times. default is 0 means no retried. -1 means retried forever. others means retried times.
func (*BeegoHTTPRequest) SetBasicAuth ¶
func (b *BeegoHTTPRequest) SetBasicAuth(username, password string) *BeegoHTTPRequest
SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
func (*BeegoHTTPRequest) SetCheckRedirect ¶
func (b *BeegoHTTPRequest) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *BeegoHTTPRequest
SetCheckRedirect specifies the policy for handling redirects.
If CheckRedirect is nil, the Client uses its default policy, which is to stop after 10 consecutive requests.
func (*BeegoHTTPRequest) SetCookie ¶
func (b *BeegoHTTPRequest) SetCookie(cookie *http.Cookie) *BeegoHTTPRequest
SetCookie add cookie into request.
func (*BeegoHTTPRequest) SetEnableCookie ¶
func (b *BeegoHTTPRequest) SetEnableCookie(enable bool) *BeegoHTTPRequest
SetEnableCookie sets enable/disable cookiejar
func (*BeegoHTTPRequest) SetHost ¶
func (b *BeegoHTTPRequest) SetHost(host string) *BeegoHTTPRequest
SetHost set the request host
func (*BeegoHTTPRequest) SetProtocolVersion ¶
func (b *BeegoHTTPRequest) SetProtocolVersion(vers string) *BeegoHTTPRequest
SetProtocolVersion Set the protocol version for incoming requests. Client requests always use HTTP/1.1.
func (*BeegoHTTPRequest) SetProxy ¶
func (b *BeegoHTTPRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *BeegoHTTPRequest
SetProxy set the http proxy example:
func(req *http.Request) (*url.URL, error) { u, _ := url.ParseRequestURI("http://127.0.0.1:8118") return u, nil }
func (*BeegoHTTPRequest) SetTLSClientConfig ¶
func (b *BeegoHTTPRequest) SetTLSClientConfig(config *tls.Config) *BeegoHTTPRequest
SetTLSClientConfig sets tls connection configurations if visiting https url.
func (*BeegoHTTPRequest) SetTimeout ¶
func (b *BeegoHTTPRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *BeegoHTTPRequest
SetTimeout sets connect time out and read-write time out for BeegoRequest.
func (*BeegoHTTPRequest) SetTransport ¶
func (b *BeegoHTTPRequest) SetTransport(transport http.RoundTripper) *BeegoHTTPRequest
SetTransport set the setting transport
func (*BeegoHTTPRequest) SetUserAgent ¶
func (b *BeegoHTTPRequest) SetUserAgent(useragent string) *BeegoHTTPRequest
SetUserAgent sets User-Agent header field
func (*BeegoHTTPRequest) Setting ¶
func (b *BeegoHTTPRequest) Setting(setting BeegoHTTPSettings) *BeegoHTTPRequest
Setting Change request settings
func (*BeegoHTTPRequest) String ¶
func (b *BeegoHTTPRequest) String() (string, error)
String returns the body string in response. it calls Response inner.
func (*BeegoHTTPRequest) ToFile ¶
func (b *BeegoHTTPRequest) ToFile(filename string) error
ToFile saves the body data in response to one file. it calls Response inner.
func (*BeegoHTTPRequest) ToJSON ¶
func (b *BeegoHTTPRequest) ToJSON(v interface{}) error
ToJSON returns the map that marshals from the body bytes as json in response . it calls Response inner.
func (*BeegoHTTPRequest) ToXML ¶
func (b *BeegoHTTPRequest) ToXML(v interface{}) error
ToXML returns the map that marshals from the body bytes as xml in response . it calls Response inner.
func (*BeegoHTTPRequest) ToYAML ¶
func (b *BeegoHTTPRequest) ToYAML(v interface{}) error
ToYAML returns the map that marshals from the body bytes as yaml in response . it calls Response inner.
func (*BeegoHTTPRequest) XMLBody ¶
func (b *BeegoHTTPRequest) XMLBody(obj interface{}) (*BeegoHTTPRequest, error)
XMLBody adds request raw body encoding by XML.
func (*BeegoHTTPRequest) YAMLBody ¶
func (b *BeegoHTTPRequest) YAMLBody(obj interface{}) (*BeegoHTTPRequest, error)
YAMLBody adds request raw body encoding by YAML.
type BeegoHTTPSettings ¶
type BeegoHTTPSettings struct { ShowDebug bool UserAgent string ConnectTimeout time.Duration ReadWriteTimeout time.Duration TLSClientConfig *tls.Config Proxy func(*http.Request) (*url.URL, error) Transport http.RoundTripper CheckRedirect func(req *http.Request, via []*http.Request) error EnableCookie bool Gzip bool DumpBody bool Retries int // if set to -1 means will retry forever }
BeegoHTTPSettings is the http.Client setting
type JsonToMapValue ¶
type JsonToMapValue struct {
Value map[string]interface{}
}
func JsonToMap ¶
func JsonToMap(value []byte) (*JsonToMapValue, error)
func (*JsonToMapValue) Get ¶
func (j *JsonToMapValue) Get(key ...string) (int, interface{}, string, error)
* zh: 返回值说明 param 1: int, 返回值的类型,
1为 interface{}值类型, 2为 空(nil)
param 2: 如果param为 1,则此返回值是有效返回值 en: The description of return values param 1: int, the type of return,
1 is interface{}, type of value, 2 is null(nil)
param 2: if param is 1,the return value is a valid return value.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package yaml implements YAML support for the Go language.
|
Package yaml implements YAML support for the Go language. |