SDK Installation
go get github.com/unkeyed/unkey/sdks/golang
Example
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 {
}
}
Error Handling
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.
Error Object | Status Code | Content Type |
---|
sdkerrors.ErrBadRequest | 400 | application/json |
sdkerrors.ErrUnauthorized | 401 | application/json |
sdkerrors.ErrForbidden | 403 | application/json |
sdkerrors.ErrNotFound | 404 | application/json |
sdkerrors.ErrConflict | 409 | application/json |
sdkerrors.ErrTooManyRequests | 429 | application/json |
sdkerrors.ErrInternalServerError | 500 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
Example
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())
}
}
}