// Create a client and send an HTTP request client := swagger.NewAPIClient(swagger.NewConfiguration()) params := swagger.NewGetPetByIdParams().WithID(42) resp, err := client.Default.GetPetById(params) // Process the HTTP response from the server if err != nil { log.Fatal(err) } defer resp.Body.Close() // Decode the response body as JSON var pet swagger.Pet err := json.NewDecoder(resp.Body).Decode(&pet) // Check for errors and handle the response data if err != nil { log.Fatal(err) } fmt.Printf("Found pet: %s (ID %d)", pet.Name, pet.ID)
// Create a client and send an HTTP request client := swagger.NewAPIClient(swagger.NewConfiguration()) params := swagger.NewGetPetByIdParams().WithID(42) resp, err := client.Default.GetPetById(params) // Check the HTTP response status code if err != nil { log.Fatal(err) } defer resp.Body.Close() if resp.IsOK() { // Process the response body var pet swagger.Pet err := json.NewDecoder(resp.Body).Decode(&pet) if err != nil { log.Fatal(err) } fmt.Printf("Found pet: %s (ID %d)", pet.Name, pet.ID) } else { // Handle the error condition fmt.Printf("Error: %d %s", resp.StatusCode(), resp.Status()) }In this example, we use the `IsOK()` method to check whether the server responded with a successful status code (i.e., 200 OK). We can then handle the response appropriately based on whether it succeeded or failed. To use the Response module, you'll need to import the `github.com/go-openapi/runtime` package into your Go program.