add convenience function g.Client for ghttp.Client

This commit is contained in:
John
2020-03-29 09:52:37 +08:00
parent 8ecd62d3de
commit 4844eea0ab
5 changed files with 22 additions and 3 deletions

View File

@ -1,9 +1,10 @@
package main
import (
_ "github.com/gogf/gf/os/gres/testdata/example/boot"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
_ "github.com/gogf/gf/os/gres/testdata/example/boot"
)
func main() {

View File

@ -1263,6 +1263,18 @@ func Test_Model_Where_ISNULL_2(t *testing.T) {
t.Assert(result[0]["id"].Int(), 1)
})
}
func Test_Model_Where_GTime(t *testing.T) {
table := createInitTable()
defer dropTable(table)
gtest.C(t, func(t *gtest.T) {
result, err := db.Table(table).Where("create_time>?", gtime.NewFromStr("2010-09-01")).All()
t.Assert(err, nil)
t.Assert(len(result), 10)
})
}
func Test_Model_WherePri(t *testing.T) {
table := createInitTable()
defer dropTable(table)

View File

@ -20,6 +20,11 @@ import (
"github.com/gogf/gf/os/gview"
)
// Client is a convenience function, that creates and returns a new HTTP client.
func Client() *ghttp.Client {
return ghttp.NewClient()
}
// Server returns an instance of http server with specified name.
func Server(name ...interface{}) *ghttp.Server {
return gins.Server(name...)

View File

@ -36,7 +36,7 @@ func NewClient() *Client {
return &Client{
Client: http.Client{
Transport: &http.Transport{
// No validation for https certification of the server.
// No validation for https certification of the server in default.
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},

View File

@ -13,6 +13,7 @@ import (
"fmt"
"github.com/gogf/gf/encoding/gparser"
"github.com/gogf/gf/text/gregex"
"github.com/gogf/gf/text/gstr"
"github.com/gogf/gf/util/gconv"
"io"
"mime/multipart"
@ -88,7 +89,7 @@ func (c *Client) Trace(url string, data ...interface{}) (*ClientResponse, error)
func (c *Client) DoRequest(method, url string, data ...interface{}) (resp *ClientResponse, err error) {
method = strings.ToUpper(method)
if len(c.prefix) > 0 {
url = c.prefix + url
url = c.prefix + gstr.Trim(url)
}
param := ""
if len(data) > 0 {