go get github.com/unkeyed/unkey/sdks/golang
package main
import (
"context"
unkey "github.com/unkeyed/unkey/sdks/golang"
"github.com/unkeyed/unkey/sdks/golang/models/components"
"github.com/unkeyed/unkey/sdks/golang/models/operations"
"log"
)
func main() {
s := unkey.New(
unkey.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
request := operations.CreateAPIRequestBody{
Name: "my-api",
}
ctx := context.Background()
res, err := s.CreateAPI(ctx, request)
if err != nil {
log.Fatal(err)
}
if res != nil {
}
}
Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both. When specified by the OpenAPI spec document, the SDK will return the appropriate subclass.
package main
import (
"context"
"errors"
unkey "github.com/unkeyed/unkey/sdks/golang"
"github.com/unkeyed/unkey/sdks/golang/models/components"
"github.com/unkeyed/unkey/sdks/golang/models/operations"
"github.com/unkeyed/unkey/sdks/golang/models/sdkerrors"
"log"
)
func main() {
s := unkey.New(
unkey.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
request := operations.CreateAPIRequestBody{
Name: "my-api",
}
ctx := context.Background()
res, err := s.CreateAPI(ctx, request)
if err != nil {
var e *sdkerrors.ErrBadRequest
if errors.As(err, &e) {
log.Fatal(e.Error())
}
var e *sdkerrors.ErrUnauthorized
if errors.As(err, &e) {
log.Fatal(e.Error())
}
var e *sdkerrors.ErrForbidden
if errors.As(err, &e) {
log.Fatal(e.Error())
}
var e *sdkerrors.ErrNotFound
if errors.As(err, &e) {
log.Fatal(e.Error())
}
var e *sdkerrors.ErrConflict
if errors.As(err, &e) {
log.Fatal(e.Error())
}
var e *sdkerrors.ErrTooManyRequests
if errors.As(err, &e) {
log.Fatal(e.Error())
}
var e *sdkerrors.ErrInternalServerError
if errors.As(err, &e) {
log.Fatal(e.Error())
}
var e *sdkerrors.SDKError
if errors.As(err, &e) {
log.Fatal(e.Error())
}
}
}