import ( "github.com/go-swagger/go-swagger/client" "github.com/go-swagger/go-swagger/client/operations" ) func main() { client := client.NewHTTPClientWithConfig(nil, &operations.Config{ BaseURL: "https://api.example.com", }) req, _ := operations.NewAddUserParams() body := operations.AddUserBody{ Name: "John", Email: "[email protected]", } req.SetBodyParam(body) resp, err := client.Operations.AddUser(req) if err != nil { fmt.Println(err) return } fmt.Println(resp.Payload) }
import ( "github.com/go-swagger/go-swagger/client" ) func main() { client := client.NewHTTPClient(nil) req, _ := http.NewRequest("POST", "https://api.example.com/user", nil) body := map[string]interface{}{ "name": "John", "email": "[email protected]", } req.SetBodyParam(body) resp, err := client.Do(req) if err != nil { fmt.Println(err) return } fmt.Println(resp.StatusCode) }This example sets the request body parameter of an HTTP request to a map of key-value pairs.