Skip to content

Instantly share code, notes, and snippets.

@gen1us2k
Created March 29, 2022 16:53
Show Gist options
  • Select an option

  • Save gen1us2k/dcecd9d8f067bed5e21f64335527a360 to your computer and use it in GitHub Desktop.

Select an option

Save gen1us2k/dcecd9d8f067bed5e21f64335527a360 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"net/http"
"os"
client "github.com/ory/hydra-client-go"
)
func main() {
consentChallenge := "consentChallenge_example" // string |
configuration := client.NewConfiguration()
configuration.Servers = []client.ServerConfiguration{
{
URL: "http://localhost:4445", // Admin API
},
}
apiClient := client.NewAPIClient(configuration)
resp, r, err := apiClient.AdminApi.GetConsentRequest(context.Background()).ConsentChallenge(consentChallenge).Execute()
if err != nil {
switch r.StatusCode {
case http.StatusNotFound:
notFound, ok := err.(*client.GenericOpenAPIError).Model().(client.JsonError)
fmt.Println(ok)
fmt.Println(*notFound.ErrorDescription)
case http.StatusGone:
r, ok := err.(*client.GenericOpenAPIError).Model().(client.RequestWasHandledResponse)
fmt.Println(r, ok)
fmt.Println("It's gone")
default:
fmt.Fprintf(os.Stderr, "Error when calling `AdminApi.GetConsentRequest``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
}
// response from `GetConsentRequest`: ConsentRequest
fmt.Fprintf(os.Stdout, "Response from `AdminApi.GetConsentRequest`: %v\n", resp)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment