Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Echo ¶
func Echo() (string, func())
Echo a request's method and payload in JSON.
Example ¶
package main
import (
"fmt"
"github.com/hoanhan101/request"
"github.com/hoanhan101/requesttest"
)
// Response describes a response from requesttest.Echo().
type Response struct {
Method string `json:"method"`
Payload interface{} `json:"payload"`
}
func main() {
url, closer := requesttest.Echo()
defer closer()
r := new(Response)
err := request.GetJSON(
&request.Options{
URL: url,
Payload: map[string]string{"k1": "v1"},
},
r,
)
if err != nil {
fmt.Println(err)
}
fmt.Printf("%+v\n", r)
}
Output: &{Method:GET Payload:k1=v1}
func Mock ¶
func Mock(response interface{}) (string, func())
Mock a JSON response.
Example ¶
package main
import (
"fmt"
"github.com/hoanhan101/request"
"github.com/hoanhan101/requesttest"
)
// Response describes a response from requesttest.Echo().
type Response struct {
Method string `json:"method"`
Payload interface{} `json:"payload"`
}
func main() {
url, closer := requesttest.Mock(`{"method":"GET","payload":{"k1":"k2"}}`)
defer closer()
r := new(Response)
err := request.GetJSON(
&request.Options{
URL: url,
},
r,
)
if err != nil {
fmt.Println(err)
}
fmt.Printf("%+v\n", r)
}
Output: &{Method:GET Payload:map[k1:k2]}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.