mirror of
https://github.com/guonaihong/gout
synced 2025-12-24 12:58:00 +08:00
2
.github/workflows/go.yml
vendored
2
.github/workflows/go.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
go: ['1.15', '1.16', '1.17', '1.18', '1.19', '1.20']
|
||||
go: ['1.18', '1.19', '1.20', '1.21', '1.22', '1.23']
|
||||
name: Go ${{ matrix.go }} sample
|
||||
|
||||
steps:
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/guonaihong/gout/debug"
|
||||
@@ -132,13 +134,18 @@ func (df *DataFlow) SetURL(url string, urlStruct ...interface{}) *DataFlow {
|
||||
return df
|
||||
}
|
||||
|
||||
if df.Req.url == "" && df.Req.req == nil {
|
||||
df.Req, df.Err = reqDef(df.method, cleanPaths(url), df.out, urlStruct...)
|
||||
return df
|
||||
if len(urlStruct) > 0 {
|
||||
var out strings.Builder
|
||||
tpl := template.Must(template.New(url).Parse(url))
|
||||
err := tpl.Execute(&out, urlStruct[0])
|
||||
if err != nil {
|
||||
df.Err = err
|
||||
return df
|
||||
}
|
||||
url = out.String()
|
||||
}
|
||||
|
||||
df.Req.url = modifyURL(cleanPaths(url))
|
||||
|
||||
return df
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/guonaihong/gout/core"
|
||||
"github.com/guonaihong/gout/middler"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -216,6 +217,7 @@ func setupForm(t *testing.T, reqTestForm testForm) *gin.Engine {
|
||||
assert.Equal(t, reqTestForm.Text, t2.Text)
|
||||
*/
|
||||
})
|
||||
|
||||
return router
|
||||
}
|
||||
|
||||
@@ -616,6 +618,29 @@ func Test_DataFlow_SetURL(t *testing.T) {
|
||||
err = New().GET("123456").SetURL(ts.URL).SetBody(body).BindBody(&s).Do()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, body, s)
|
||||
|
||||
// New test case to check if the body can be read when SetBody is called before SetMethod
|
||||
s = ""
|
||||
ts2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
bodyBytes, _ := io.ReadAll(r.Body)
|
||||
w.Write(bodyBytes)
|
||||
}))
|
||||
defer ts2.Close()
|
||||
|
||||
err = New().
|
||||
WithContext(context.Background()).
|
||||
SetTimeout(time.Second * 100).
|
||||
SetURL(ts2.URL).
|
||||
SetBody("22222").
|
||||
SetMethod("POST").
|
||||
RequestUse(middler.WithRequestMiddlerFunc(func(req *http.Request) error {
|
||||
bytes, _ := io.ReadAll(req.Body)
|
||||
assert.Equal(t, "22222", string(bytes))
|
||||
req.Body = io.NopCloser(strings.NewReader("22222"))
|
||||
return nil
|
||||
})).
|
||||
Do()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func Test_DataFlow_SetHost(t *testing.T) {
|
||||
@@ -695,6 +720,7 @@ func Test_DataFlow_Bind(t *testing.T) {
|
||||
// 测试错误的情况
|
||||
router := func() *gin.Engine {
|
||||
router := gin.New()
|
||||
|
||||
router.GET("/", func(c *gin.Context) {
|
||||
c.String(200, "test SetDecod3")
|
||||
})
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
||||
module github.com/guonaihong/gout
|
||||
|
||||
go 1.17
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.4
|
||||
|
||||
1
go.sum
1
go.sum
@@ -90,7 +90,6 @@ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
|
||||
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||
|
||||
Reference in New Issue
Block a user