gohttp
gohttp copied to clipboard
Get a error when running test case
Hi, @nahid Get a error when running test case:
- Error
error 1 :
# command-line-arguments
./test_post.go:22:11: resp.GetBodyWithUnmarshal undefined (type *gohttp.Response has no field or method GetBodyWithUnmarshal)
error 2 :
# command-line-arguments
./test_async_post.go:28:17: op.GetBodyAsString undefined (type *gohttp.AsyncResponse has no field or method GetBodyAsString)
- Code 1:
package main
import (
"github.com/nahid/gohttp"
"fmt"
)
func main() {
req := gohttp.NewRequest()
resp, err := req.
FormData(map[string]string{"name": "Nahid"}).
Post("https://httpbin.org/post")
if err != nil {
panic(err)
}
if resp.GetStatusCode() == 200 {
var resps map[string]interface{}
_ = resp.GetBodyWithUnmarshal(&resps)
fmt.Println(resps["form"])
}
}
- Code 2:
package main
import (
"github.com/nahid/gohttp"
"fmt"
)
func main() {
req := gohttp.NewRequest()
ch := make(chan *gohttp.AsyncResponse)
var users [3]string
users[0] = "nahid"
users[1] = "shipu"
users[2] = "sujan"
for i:=0; i<len(users); i++ {
req.
FormData(map[string]string{"user": users[i]}).
AsyncPost("https://httpbin.org/post", ch)
}
for i:=0; i<len(users); i++ {
op := <-ch
fmt.Println(op.GetBodyAsString())
}
}
- Expectation test case work.
The op type is the AsyncResponse.
type AsyncResponse struct {
Resp *Response
Err error
}
I change this line with:
fmt.Println(op.Resp.GetBodyAsString())
It can work.