bannerify

package module
v0.1.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README

Bannerify Go API Library

Go Reference

The Bannerify Go library provides convenient access to the Bannerify REST API from applications written in Go. The full API of this library can be found in api.md.

It is generated with Stainless.

Installation

import (
	"github.com/bannerify/bannerify-go" // imported as bannerify
)

Or to pin the version:

go get -u 'github.com/bannerify/bannerify-go@v0.1.0-alpha.1'

Requirements

This library requires Go 1.18+.

Usage

The full API of this library can be found in api.md.

package main

import (
	"context"
	"fmt"

	"github.com/bannerify/bannerify-go"
)

func main() {
	client := bannerify.NewClient()
	v1LivenessResponse, err := client.V1.Liveness(context.TODO())
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", v1LivenessResponse.Services)
}

Request fields

All request parameters are wrapped in a generic Field type, which we use to distinguish zero values from null or omitted fields.

This prevents accidentally sending a zero value if you forget a required parameter, and enables explicitly sending null, false, '', or 0 on optional parameters. Any field not specified is not sent.

To construct fields with values, use the helpers String(), Int(), Float(), or most commonly, the generic F[T](). To send a null, use Null[T](), and to send a nonconforming value, use Raw[T](any). For example:

params := FooParams{
	Name: bannerify.F("hello"),

	// Explicitly send `"description": null`
	Description: bannerify.Null[string](),

	Point: bannerify.F(bannerify.Point{
		X: bannerify.Int(0),
		Y: bannerify.Int(1),

		// In cases where the API specifies a given type,
		// but you want to send something else, use `Raw`:
		Z: bannerify.Raw[int64](0.01), // sends a float
	}),
}
Response objects

All fields in response structs are value types (not pointers or wrappers).

If a given field is null, not present, or invalid, the corresponding field will simply be its zero value.

All response structs also include a special JSON field, containing more detailed information about each property, which you can use like so:

if res.Name == "" {
	// true if `"name"` is either not present or explicitly null
	res.JSON.Name.IsNull()

	// true if the `"name"` key was not present in the repsonse JSON at all
	res.JSON.Name.IsMissing()

	// When the API returns data that cannot be coerced to the expected type:
	if res.JSON.Name.IsInvalid() {
		raw := res.JSON.Name.Raw()

		legacyName := struct{
			First string `json:"first"`
			Last  string `json:"last"`
		}{}
		json.Unmarshal([]byte(raw), &legacyName)
		name = legacyName.First + " " + legacyName.Last
	}
}

These .JSON structs also include an Extras map containing any properties in the json response that were not specified in the struct. This can be useful for API features not yet present in the SDK.

body := res.JSON.ExtraFields["my_unexpected_field"].Raw()
RequestOptions

This library uses the functional options pattern. Functions defined in the option package return a RequestOption, which is a closure that mutates a RequestConfig. These options can be supplied to the client or at individual requests. For example:

client := bannerify.NewClient(
	// Adds a header to every request made by the client
	option.WithHeader("X-Some-Header", "custom_header_info"),
)

client.V1.Liveness(context.TODO(), ...,
	// Override the header
	option.WithHeader("X-Some-Header", "some_other_custom_header_info"),
	// Add an undocumented field to the request body, using sjson syntax
	option.WithJSONSet("some.json.path", map[string]string{"my": "object"}),
)

See the full list of request options.

Pagination

This library provides some conveniences for working with paginated list endpoints.

You can use .ListAutoPaging() methods to iterate through items across all pages:

Or you can use simple .List() methods to fetch a single page and receive a standard response object with additional helper methods like .GetNextPage(), e.g.:

Errors

When the API returns a non-success status code, we return an error with type *bannerify.Error. This contains the StatusCode, *http.Request, and *http.Response values of the request, as well as the JSON of the error body (much like other response objects in the SDK).

To handle errors, we recommend that you use the errors.As pattern:

_, err := client.V1.Liveness(context.TODO())
if err != nil {
	var apierr *bannerify.Error
	if errors.As(err, &apierr) {
		println(string(apierr.DumpRequest(true)))  // Prints the serialized HTTP request
		println(string(apierr.DumpResponse(true))) // Prints the serialized HTTP response
	}
	panic(err.Error()) // GET "/v1/liveness": 400 Bad Request { ... }
}

When other errors occur, they are returned unwrapped; for example, if HTTP transport fails, you might receive *url.Error wrapping *net.OpError.

Timeouts

Requests do not time out by default; use context to configure a timeout for a request lifecycle.

Note that if a request is retried, the context timeout does not start over. To set a per-retry timeout, use option.WithRequestTimeout().

// This sets the timeout for the request, including all the retries.
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
client.V1.Liveness(
	ctx,
	// This sets the per-retry timeout
	option.WithRequestTimeout(20*time.Second),
)
File uploads

Request parameters that correspond to file uploads in multipart requests are typed as param.Field[io.Reader]. The contents of the io.Reader will by default be sent as a multipart form part with the file name of "anonymous_file" and content-type of "application/octet-stream".

The file name and content-type can be customized by implementing Name() string or ContentType() string on the run-time type of io.Reader. Note that os.File implements Name() string, so a file returned by os.Open will be sent with the file name on disk.

We also provide a helper bannerify.FileParam(reader io.Reader, filename string, contentType string) which can be used to wrap any io.Reader with the appropriate file name and content type.

Retries

Certain errors will be automatically retried 2 times by default, with a short exponential backoff. We retry by default all connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors.

You can use the WithMaxRetries option to configure or disable this:

// Configure the default for all requests:
client := bannerify.NewClient(
	option.WithMaxRetries(0), // default is 2
)

// Override per-request:
client.V1.Liveness(context.TODO(), option.WithMaxRetries(5))
Making custom/undocumented requests

This library is typed for convenient access to the documented API. If you need to access undocumented endpoints, params, or response properties, the library can still be used.

Undocumented endpoints

To make requests to undocumented endpoints, you can use client.Get, client.Post, and other HTTP verbs. RequestOptions on the client, such as retries, will be respected when making these requests.

var (
    // params can be an io.Reader, a []byte, an encoding/json serializable object,
    // or a "…Params" struct defined in this library.
    params map[string]interface{}

    // result can be an []byte, *http.Response, a encoding/json deserializable object,
    // or a model defined in this library.
    result *http.Response
)
err := client.Post(context.Background(), "/unspecified", params, &result)
if err != nil {
    …
}
Undocumented request params

To make requests using undocumented parameters, you may use either the option.WithQuerySet() or the option.WithJSONSet() methods.

params := FooNewParams{
    ID:   bannerify.F("id_xxxx"),
    Data: bannerify.F(FooNewParamsData{
        FirstName: bannerify.F("John"),
    }),
}
client.Foo.New(context.Background(), params, option.WithJSONSet("data.last_name", "Doe"))
Undocumented response properties

To access undocumented response properties, you may either access the raw JSON of the response as a string with result.JSON.RawJSON(), or get the raw JSON of a particular field on the result with result.JSON.Foo.Raw().

Any fields that are not present on the response struct will be saved and can be accessed by result.JSON.ExtraFields() which returns the extra fields as a map[string]Field.

Middleware

We provide option.WithMiddleware which applies the given middleware to requests.

func Logger(req *http.Request, next option.MiddlewareNext) (res *http.Response, err error) {
	// Before the request
	start := time.Now()
	LogReq(req)

	// Forward the request to the next handler
	res, err = next(req)

	// Handle stuff after the request
	end := time.Now()
	LogRes(res, err, start - end)

    return res, err
}

client := bannerify.NewClient(
	option.WithMiddleware(Logger),
)

When multiple middlewares are provided as variadic arguments, the middlewares are applied left to right. If option.WithMiddleware is given multiple times, for example first in the client then the method, the middleware in the client will run first and the middleware given in the method will run next.

You may also replace the default http.Client with option.WithHTTPClient(client). Only one http client is accepted (this overwrites any previous client) and receives requests after any middleware has been applied.

Semantic versioning

This package generally follows SemVer conventions, though certain backwards-incompatible changes may be released as minor versions:

  1. Changes to library internals which are technically public but not intended or documented for external use. (Please open a GitHub issue to let us know if you are relying on such internals).
  2. Changes that we do not expect to impact the vast majority of users in practice.

We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.

We are keen for your feedback; please open an issue with questions, bugs, or suggestions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(value bool) param.Field[bool]

Bool is a param field helper which helps specify bools.

func F

func F[T any](value T) param.Field[T]

F is a param field helper used to initialize a param.Field generic struct. This helps specify null, zero values, and overrides, as well as normal values. You can read more about this in our README.

func FileParam

func FileParam(reader io.Reader, filename string, contentType string) param.Field[io.Reader]

FileParam is a param field helper which helps files with a mime content-type.

func Float

func Float(value float64) param.Field[float64]

Float is a param field helper which helps specify floats.

func Int

func Int(value int64) param.Field[int64]

Int is a param field helper which helps specify integers. This is particularly helpful when specifying integer constants for fields.

func Null

func Null[T any]() param.Field[T]

Null is a param field helper which explicitly sends null to the API.

func Raw

func Raw[T any](value any) param.Field[T]

Raw is a param field helper for specifying values for fields when the type you are looking to send is different from the type that is specified in the SDK. For example, if the type of the field is an integer, but you want to send a float, you could do that by setting the corresponding field with Raw[int](0.5).

func String

func String(value string) param.Field[string]

String is a param field helper which helps specify strings.

Types

type APIDeleteAPIParams

type APIDeleteAPIParams struct {
	// The id of the api to delete
	APIID param.Field[string] `json:"apiId,required"`
}

func (APIDeleteAPIParams) MarshalJSON

func (r APIDeleteAPIParams) MarshalJSON() (data []byte, err error)

type APIDeleteAPIResponse

type APIDeleteAPIResponse = interface{}

type APIKeyListParams

type APIKeyListParams struct {
	// The maximum number of keys to return
	Limit param.Field[int64] `query:"limit"`
	// Use this to fetch the next page of results. A new cursor will be returned in the
	// response if there are more results.
	Offset param.Field[float64] `query:"offset"`
	// If provided, this will only return keys where the `ownerId` matches.
	OwnerID param.Field[string] `query:"ownerId"`
}

func (APIKeyListParams) URLQuery

func (r APIKeyListParams) URLQuery() (v url.Values)

URLQuery serializes APIKeyListParams's query parameters as `url.Values`.

type APIKeyListResponse

type APIKeyListResponse struct {
	Keys []APIKeyListResponseKey `json:"keys,required"`
	// The total number of keys for this api
	Total int64                  `json:"total,required"`
	JSON  apiKeyListResponseJSON `json:"-"`
}

func (*APIKeyListResponse) UnmarshalJSON

func (r *APIKeyListResponse) UnmarshalJSON(data []byte) (err error)

type APIKeyListResponseKey

type APIKeyListResponseKey struct {
	// The id of the key
	ID string `json:"id,required"`
	// The unix timestamp in milliseconds when the key was created
	CreatedAt int64 `json:"createdAt,required"`
	// The first few characters of the key to visually identify it
	Start string `json:"start,required"`
	// The id of the workspace that owns the key
	WorkspaceID string `json:"workspaceId,required"`
	// The id of the api that this key is for
	APIID string `json:"apiId"`
	// The unix timestamp in milliseconds when the key was deleted. We don't delete the
	// key outright, you can restore it later.
	DeletedAt int64 `json:"deletedAt"`
	// Sets if key is enabled or disabled. Disabled keys are not valid.
	Enabled bool `json:"enabled"`
	// The unix timestamp in milliseconds when the key will expire. If this field is
	// null or undefined, the key is not expiring.
	Expires int64 `json:"expires"`
	// The identity of the key
	Identity APIKeyListResponseKeysIdentity `json:"identity"`
	// Any additional metadata you want to store with the key
	Meta map[string]interface{} `json:"meta"`
	// The name of the key, give keys a name to easily identify their purpose
	Name string `json:"name"`
	// The id of the tenant associated with this key. Use whatever reference you have
	// in your system to identify the tenant. When verifying the key, we will send this
	// field back to you, so you know who is accessing your API.
	OwnerID string `json:"ownerId"`
	// All permissions this key has
	Permissions []string `json:"permissions"`
	// The key in plaintext
	Plaintext string `json:"plaintext"`
	// Unkey comes with per-key ratelimiting out of the box.
	Ratelimit APIKeyListResponseKeysRatelimit `json:"ratelimit"`
	// Unkey allows you to refill remaining verifications on a key on a regular
	// interval.
	Refill APIKeyListResponseKeysRefill `json:"refill"`
	// The number of requests that can be made with this key before it becomes invalid.
	// If this field is null or undefined, the key has no request limit.
	Remaining int64 `json:"remaining"`
	// All roles this key belongs to
	Roles []string `json:"roles"`
	// The unix timestamp in milliseconds when the key was last updated
	UpdatedAt int64                     `json:"updatedAt"`
	JSON      apiKeyListResponseKeyJSON `json:"-"`
}

func (*APIKeyListResponseKey) UnmarshalJSON

func (r *APIKeyListResponseKey) UnmarshalJSON(data []byte) (err error)

type APIKeyListResponseKeysIdentity

type APIKeyListResponseKeysIdentity struct {
	// The id of the identity
	ID string `json:"id,required"`
	// The external id of the identity
	ExternalID string `json:"externalId,required"`
	// Any additional metadata attached to the identity
	Meta map[string]interface{}             `json:"meta"`
	JSON apiKeyListResponseKeysIdentityJSON `json:"-"`
}

The identity of the key

func (*APIKeyListResponseKeysIdentity) UnmarshalJSON

func (r *APIKeyListResponseKeysIdentity) UnmarshalJSON(data []byte) (err error)

type APIKeyListResponseKeysRatelimit

type APIKeyListResponseKeysRatelimit struct {
	Async bool `json:"async,required"`
	// The duration of the ratelimit window, in milliseconds.
	Duration int64 `json:"duration,required"`
	// The total amount of burstable requests.
	Limit int64 `json:"limit,required"`
	// Determines the speed at which tokens are refilled, in milliseconds.
	RefillInterval int64 `json:"refillInterval"`
	// How many tokens to refill during each refillInterval.
	RefillRate int64 `json:"refillRate"`
	// Fast ratelimiting doesn't add latency, while consistent ratelimiting is more
	// accurate.
	Type APIKeyListResponseKeysRatelimitType `json:"type"`
	JSON apiKeyListResponseKeysRatelimitJSON `json:"-"`
}

Unkey comes with per-key ratelimiting out of the box.

func (*APIKeyListResponseKeysRatelimit) UnmarshalJSON

func (r *APIKeyListResponseKeysRatelimit) UnmarshalJSON(data []byte) (err error)

type APIKeyListResponseKeysRatelimitType

type APIKeyListResponseKeysRatelimitType string

Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate.

const (
	APIKeyListResponseKeysRatelimitTypeFast       APIKeyListResponseKeysRatelimitType = "fast"
	APIKeyListResponseKeysRatelimitTypeConsistent APIKeyListResponseKeysRatelimitType = "consistent"
)

func (APIKeyListResponseKeysRatelimitType) IsKnown

type APIKeyListResponseKeysRefill

type APIKeyListResponseKeysRefill struct {
	// Resets `remaining` to this value every interval.
	Amount int64 `json:"amount,required"`
	// Determines the rate at which verifications will be refilled.
	Interval APIKeyListResponseKeysRefillInterval `json:"interval,required"`
	// The unix timestamp in miliseconds when the key was last refilled.
	LastRefillAt int64                            `json:"lastRefillAt"`
	JSON         apiKeyListResponseKeysRefillJSON `json:"-"`
}

Unkey allows you to refill remaining verifications on a key on a regular interval.

func (*APIKeyListResponseKeysRefill) UnmarshalJSON

func (r *APIKeyListResponseKeysRefill) UnmarshalJSON(data []byte) (err error)

type APIKeyListResponseKeysRefillInterval

type APIKeyListResponseKeysRefillInterval string

Determines the rate at which verifications will be refilled.

const (
	APIKeyListResponseKeysRefillIntervalDaily   APIKeyListResponseKeysRefillInterval = "daily"
	APIKeyListResponseKeysRefillIntervalMonthly APIKeyListResponseKeysRefillInterval = "monthly"
)

func (APIKeyListResponseKeysRefillInterval) IsKnown

type APIKeyService

type APIKeyService struct {
	Options []option.RequestOption
}

APIKeyService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewAPIKeyService method instead.

func NewAPIKeyService

func NewAPIKeyService(opts ...option.RequestOption) (r *APIKeyService)

NewAPIKeyService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*APIKeyService) List

func (r *APIKeyService) List(ctx context.Context, apiID string, query APIKeyListParams, opts ...option.RequestOption) (res *APIKeyListResponse, err error)

type APIService

type APIService struct {
	Options []option.RequestOption
	Keys    *APIKeyService
}

APIService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewAPIService method instead.

func NewAPIService

func NewAPIService(opts ...option.RequestOption) (r *APIService)

NewAPIService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*APIService) DeleteAPI

func (r *APIService) DeleteAPI(ctx context.Context, body APIDeleteAPIParams, opts ...option.RequestOption) (res *APIDeleteAPIResponse, err error)

type Client

type Client struct {
	Options    []option.RequestOption
	V1         *V1Service
	APIs       *APIService
	Ratelimits *RatelimitService
	Keys       *KeyService
}

Client creates a struct with services and top level methods that help with interacting with the bannerify API. You should not instantiate this client directly, and instead use the NewClient method instead.

func NewClient

func NewClient(opts ...option.RequestOption) (r *Client)

NewClient generates a new client with the default option read from the environment (). The option passed in as arguments are applied after these default arguments, and all option will be passed down to the services and requests that this client makes.

func (*Client) Delete

func (r *Client) Delete(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Delete makes a DELETE request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Execute

func (r *Client) Execute(ctx context.Context, method string, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Execute makes a request with the given context, method, URL, request params, response, and request options. This is useful for hitting undocumented endpoints while retaining the base URL, auth, retries, and other options from the client.

If a byte slice or an io.Reader is supplied to params, it will be used as-is for the request body.

The params is by default serialized into the body using encoding/json. If your type implements a MarshalJSON function, it will be used instead to serialize the request. If a URLQuery method is implemented, the returned url.Values will be used as query strings to the url.

If your params struct uses param.Field, you must provide either [MarshalJSON], [URLQuery], and/or [MarshalForm] functions. It is undefined behavior to use a struct uses param.Field without specifying how it is serialized.

Any "…Params" object defined in this library can be used as the request argument. Note that 'path' arguments will not be forwarded into the url.

The response body will be deserialized into the res variable, depending on its type:

  • A pointer to a *http.Response is populated by the raw response.
  • A pointer to a byte array will be populated with the contents of the request body.
  • A pointer to any other type uses this library's default JSON decoding, which respects UnmarshalJSON if it is defined on the type.
  • A nil value will not read the response body.

For even greater flexibility, see option.WithResponseInto and option.WithResponseBodyInto.

func (*Client) Get

func (r *Client) Get(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Get makes a GET request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Patch

func (r *Client) Patch(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Patch makes a PATCH request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Post

func (r *Client) Post(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Post makes a POST request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Put

func (r *Client) Put(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Put makes a PUT request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

type Error

type Error = apierror.Error

type KeyNewParams

type KeyNewParams struct {
	// Choose an `API` where this key should be created.
	APIID param.Field[string] `json:"apiId,required"`
	// The byte length used to generate your key determines its entropy as well as its
	// length. Higher is better, but keys become longer and more annoying to handle.
	// The default is 16 bytes, or 2^^128 possible combinations.
	ByteLength param.Field[int64] `json:"byteLength"`
	// You can auto expire keys by providing a unix timestamp in milliseconds. Once
	// Keys expire they will automatically be disabled and are no longer valid unless
	// you enable them again.
	Expires param.Field[int64] `json:"expires"`
	// This is a place for dynamic meta data, anything that feels useful for you should
	// go here
	Meta param.Field[map[string]interface{}] `json:"meta"`
	// The name for your Key. This is not customer facing.
	Name param.Field[string] `json:"name"`
	// Your user’s Id. This will provide a link between Unkey and your customer record.
	// When validating a key, we will return this back to you, so you can clearly
	// identify your user from their api key.
	OwnerID param.Field[string] `json:"ownerId"`
	// To make it easier for your users to understand which product an api key belongs
	// to, you can add prefix them.
	//
	// For example Stripe famously prefixes their customer ids with cus* or their api
	// keys with sk_live*.
	//
	// The underscore is automatically added if you are defining a prefix, for example:
	// "prefix": "abc" will result in a key like abc_xxxxxxxxx
	Prefix param.Field[string] `json:"prefix"`
	// Unkey comes with per-key ratelimiting out of the box.
	Ratelimit param.Field[KeyNewParamsRatelimit] `json:"ratelimit"`
	// You can limit the number of requests a key can make. Once a key reaches 0
	// remaining requests, it will automatically be disabled and is no longer valid
	// unless you update it.
	Remaining param.Field[int64] `json:"remaining"`
}

func (KeyNewParams) MarshalJSON

func (r KeyNewParams) MarshalJSON() (data []byte, err error)

type KeyNewParamsRatelimit

type KeyNewParamsRatelimit struct {
	// The total amount of burstable requests.
	Limit param.Field[int64] `json:"limit,required"`
	// Determines the speed at which tokens are refilled, in milliseconds.
	RefillInterval param.Field[int64] `json:"refillInterval,required"`
	// How many tokens to refill during each refillInterval.
	RefillRate param.Field[int64] `json:"refillRate,required"`
	// Fast ratelimiting doesn't add latency, while consistent ratelimiting is more
	// accurate.
	Type param.Field[KeyNewParamsRatelimitType] `json:"type"`
}

Unkey comes with per-key ratelimiting out of the box.

func (KeyNewParamsRatelimit) MarshalJSON

func (r KeyNewParamsRatelimit) MarshalJSON() (data []byte, err error)

type KeyNewParamsRatelimitType

type KeyNewParamsRatelimitType string

Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate.

const (
	KeyNewParamsRatelimitTypeFast       KeyNewParamsRatelimitType = "fast"
	KeyNewParamsRatelimitTypeConsistent KeyNewParamsRatelimitType = "consistent"
)

func (KeyNewParamsRatelimitType) IsKnown

func (r KeyNewParamsRatelimitType) IsKnown() bool

type KeyNewResponse

type KeyNewResponse struct {
	// The newly created api key, do not store this on your own system but pass it
	// along to your user.
	Key string `json:"key,required"`
	// The id of the key. This is not a secret and can be stored as a reference if you
	// wish. You need the keyId to update or delete a key later.
	KeyID string             `json:"keyId,required"`
	JSON  keyNewResponseJSON `json:"-"`
}

func (*KeyNewResponse) UnmarshalJSON

func (r *KeyNewResponse) UnmarshalJSON(data []byte) (err error)

type KeyService

type KeyService struct {
	Options []option.RequestOption
}

KeyService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewKeyService method instead.

func NewKeyService

func NewKeyService(opts ...option.RequestOption) (r *KeyService)

NewKeyService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*KeyService) New

func (r *KeyService) New(ctx context.Context, body KeyNewParams, opts ...option.RequestOption) (res *KeyNewResponse, err error)

func (*KeyService) Verify

func (r *KeyService) Verify(ctx context.Context, body KeyVerifyParams, opts ...option.RequestOption) (res *KeyVerifyResponse, err error)

type KeyVerifyParams

type KeyVerifyParams struct {
	// The key to verify
	Key param.Field[string] `json:"key,required"`
	// The id of the api where the key belongs to. This is optional for now but will be
	// required soon. The key will be verified against the api's configuration. If the
	// key does not belong to the api, the verification will fail.
	APIID param.Field[string] `json:"apiId"`
}

func (KeyVerifyParams) MarshalJSON

func (r KeyVerifyParams) MarshalJSON() (data []byte, err error)

type KeyVerifyResponse

type KeyVerifyResponse struct {
	// Whether the key is valid or not. A key could be invalid for a number of reasons,
	// for example if it has expired, has no more verifications left or if it has been
	// deleted.
	Valid bool `json:"valid,required"`
	// If the key is invalid this field will be set to the reason why it is invalid.
	// Possible values are:
	//
	//   - NOT_FOUND: the key does not exist or has expired
	//   - FORBIDDEN: the key is not allowed to access the api
	//   - USAGE_EXCEEDED: the key has exceeded its request limit
	//   - RATE_LIMITED: the key has been ratelimited,
	//   - INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform
	//     this action
	Code KeyVerifyResponseCode `json:"code"`
	// The unix timestamp in milliseconds when the key was created
	CreatedAt int64 `json:"createdAt"`
	// The unix timestamp in milliseconds when the key was deleted. We don't delete the
	// key outright, you can restore it later.
	DeletedAt int64 `json:"deletedAt"`
	// The unix timestamp in milliseconds when the key will expire. If this field is
	// null or undefined, the key is not expiring.
	Expires int64 `json:"expires"`
	// The id of the key
	KeyID string `json:"keyId"`
	// Any additional metadata you want to store with the key
	Meta map[string]interface{} `json:"meta"`
	// The name of the key, give keys a name to easily identifiy their purpose
	Name string `json:"name"`
	// The id of the tenant associated with this key. Use whatever reference you have
	// in your system to identify the tenant. When verifying the key, we will send this
	// field back to you, so you know who is accessing your API.
	OwnerID string `json:"ownerId"`
	// The ratelimit configuration for this key. If this field is null or undefined,
	// the key has no ratelimit.
	Ratelimit KeyVerifyResponseRatelimit `json:"ratelimit"`
	// The number of requests that can be made with this key before it becomes invalid.
	// If this field is null or undefined, the key has no request limit.
	Remaining int64                 `json:"remaining"`
	JSON      keyVerifyResponseJSON `json:"-"`
}

func (*KeyVerifyResponse) UnmarshalJSON

func (r *KeyVerifyResponse) UnmarshalJSON(data []byte) (err error)

type KeyVerifyResponseCode

type KeyVerifyResponseCode string

If the key is invalid this field will be set to the reason why it is invalid. Possible values are:

  • NOT_FOUND: the key does not exist or has expired
  • FORBIDDEN: the key is not allowed to access the api
  • USAGE_EXCEEDED: the key has exceeded its request limit
  • RATE_LIMITED: the key has been ratelimited,
  • INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform this action
const (
	KeyVerifyResponseCodeNotFound                KeyVerifyResponseCode = "NOT_FOUND"
	KeyVerifyResponseCodeForbidden               KeyVerifyResponseCode = "FORBIDDEN"
	KeyVerifyResponseCodeUsageExceeded           KeyVerifyResponseCode = "USAGE_EXCEEDED"
	KeyVerifyResponseCodeRateLimited             KeyVerifyResponseCode = "RATE_LIMITED"
	KeyVerifyResponseCodeUnauthorized            KeyVerifyResponseCode = "UNAUTHORIZED"
	KeyVerifyResponseCodeDisabled                KeyVerifyResponseCode = "DISABLED"
	KeyVerifyResponseCodeInsufficientPermissions KeyVerifyResponseCode = "INSUFFICIENT_PERMISSIONS"
	KeyVerifyResponseCodeExpired                 KeyVerifyResponseCode = "EXPIRED"
)

func (KeyVerifyResponseCode) IsKnown

func (r KeyVerifyResponseCode) IsKnown() bool

type KeyVerifyResponseRatelimit

type KeyVerifyResponseRatelimit struct {
	// Maximum number of requests that can be made inside a window
	Limit int64 `json:"limit,required"`
	// Remaining requests after this verification
	Remaining int64 `json:"remaining,required"`
	// Unix timestamp in milliseconds when the ratelimit will reset
	Reset int64                          `json:"reset,required"`
	JSON  keyVerifyResponseRatelimitJSON `json:"-"`
}

The ratelimit configuration for this key. If this field is null or undefined, the key has no ratelimit.

func (*KeyVerifyResponseRatelimit) UnmarshalJSON

func (r *KeyVerifyResponseRatelimit) UnmarshalJSON(data []byte) (err error)

type RatelimitLimitParams

type RatelimitLimitParams struct {
	// The window duration in milliseconds
	Duration param.Field[int64] `json:"duration,required"`
	// Identifier of your user, this can be their userId, an email, an ip or anything
	// else.
	Identifier param.Field[string] `json:"identifier,required"`
	// How many requests may pass in a given window.
	Limit param.Field[int64] `json:"limit,required"`
	// Async will return a response immediately, lowering latency at the cost of
	// accuracy.
	Async param.Field[bool] `json:"async"`
	// Expensive requests may use up more tokens. You can specify a cost to the request
	// here and we'll deduct this many tokens in the current window. If there are not
	// enough tokens left, the request is denied.
	//
	// Set it to 0 to receive the current limit without changing anything.
	Cost param.Field[int64] `json:"cost"`
	// Attach any metadata to this request
	Meta param.Field[map[string]RatelimitLimitParamsMetaUnion] `json:"meta"`
	// Namespaces group different limits together for better analytics. You might have
	// a namespace for your public API and one for internal tRPC routes.
	Namespace param.Field[string] `json:"namespace"`
	// Resources that are about to be accessed by the user
	Resources param.Field[[]RatelimitLimitParamsResource] `json:"resources"`
}

func (RatelimitLimitParams) MarshalJSON

func (r RatelimitLimitParams) MarshalJSON() (data []byte, err error)

type RatelimitLimitParamsMetaUnion

type RatelimitLimitParamsMetaUnion interface {
	ImplementsRatelimitLimitParamsMetaUnion()
}

Satisfied by [shared.UnionString], [shared.UnionBool], [shared.UnionFloat].

type RatelimitLimitParamsResource

type RatelimitLimitParamsResource struct {
	// The unique identifier for the resource
	ID param.Field[string] `json:"id,required"`
	// The type of resource
	Type param.Field[string] `json:"type,required"`
	// Attach any metadata to this resources
	Meta param.Field[map[string]RatelimitLimitParamsResourcesMetaUnion] `json:"meta"`
	// A human readable name for this resource
	Name param.Field[string] `json:"name"`
}

func (RatelimitLimitParamsResource) MarshalJSON

func (r RatelimitLimitParamsResource) MarshalJSON() (data []byte, err error)

type RatelimitLimitParamsResourcesMetaUnion

type RatelimitLimitParamsResourcesMetaUnion interface {
	ImplementsRatelimitLimitParamsResourcesMetaUnion()
}

Satisfied by [shared.UnionString], [shared.UnionBool], [shared.UnionFloat].

type RatelimitLimitResponse

type RatelimitLimitResponse struct {
	// How many requests are allowed within a window.
	Limit int64 `json:"limit,required"`
	// How many requests can still be made in the current window.
	Remaining int64 `json:"remaining,required"`
	// A unix millisecond timestamp when the limits reset.
	Reset int64 `json:"reset,required"`
	// Returns true if the request should be processed, false if it was rejected.
	Success bool                       `json:"success,required"`
	JSON    ratelimitLimitResponseJSON `json:"-"`
}

func (*RatelimitLimitResponse) UnmarshalJSON

func (r *RatelimitLimitResponse) UnmarshalJSON(data []byte) (err error)

type RatelimitService

type RatelimitService struct {
	Options []option.RequestOption
}

RatelimitService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewRatelimitService method instead.

func NewRatelimitService

func NewRatelimitService(opts ...option.RequestOption) (r *RatelimitService)

NewRatelimitService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*RatelimitService) Limit

type V1APICreateAPINewParams

type V1APICreateAPINewParams struct {
	// The name for your API. This is not customer facing.
	Name param.Field[string] `json:"name,required"`
}

func (V1APICreateAPINewParams) MarshalJSON

func (r V1APICreateAPINewParams) MarshalJSON() (data []byte, err error)

type V1APICreateAPINewResponse

type V1APICreateAPINewResponse struct {
	// The id of the api
	APIID string                        `json:"apiId,required"`
	JSON  v1APICreateAPINewResponseJSON `json:"-"`
}

func (*V1APICreateAPINewResponse) UnmarshalJSON

func (r *V1APICreateAPINewResponse) UnmarshalJSON(data []byte) (err error)

type V1APICreateAPIService

type V1APICreateAPIService struct {
	Options []option.RequestOption
}

V1APICreateAPIService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewV1APICreateAPIService method instead.

func NewV1APICreateAPIService

func NewV1APICreateAPIService(opts ...option.RequestOption) (r *V1APICreateAPIService)

NewV1APICreateAPIService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*V1APICreateAPIService) New

type V1APIGetAPIGetParams

type V1APIGetAPIGetParams struct {
	// The id of the api to fetch
	APIID param.Field[string] `query:"apiId,required"`
}

func (V1APIGetAPIGetParams) URLQuery

func (r V1APIGetAPIGetParams) URLQuery() (v url.Values)

URLQuery serializes V1APIGetAPIGetParams's query parameters as `url.Values`.

type V1APIGetAPIGetResponse

type V1APIGetAPIGetResponse struct {
	// The id of the key
	ID string `json:"id,required"`
	// The id of the workspace that owns the api
	WorkspaceID string `json:"workspaceId,required"`
	// The name of the api. This is internal and your users will not see this.
	Name string                     `json:"name"`
	JSON v1APIGetAPIGetResponseJSON `json:"-"`
}

func (*V1APIGetAPIGetResponse) UnmarshalJSON

func (r *V1APIGetAPIGetResponse) UnmarshalJSON(data []byte) (err error)

type V1APIGetAPIService

type V1APIGetAPIService struct {
	Options []option.RequestOption
}

V1APIGetAPIService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewV1APIGetAPIService method instead.

func NewV1APIGetAPIService

func NewV1APIGetAPIService(opts ...option.RequestOption) (r *V1APIGetAPIService)

NewV1APIGetAPIService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*V1APIGetAPIService) Get

type V1APIService

type V1APIService struct {
	Options   []option.RequestOption
	GetAPI    *V1APIGetAPIService
	CreateAPI *V1APICreateAPIService
}

V1APIService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewV1APIService method instead.

func NewV1APIService

func NewV1APIService(opts ...option.RequestOption) (r *V1APIService)

NewV1APIService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

type V1KeyCreateKeyNewParams

type V1KeyCreateKeyNewParams struct {
	// Choose an `API` where this key should be created.
	APIID param.Field[string] `json:"apiId,required"`
	// The byte length used to generate your key determines its entropy as well as its
	// length. Higher is better, but keys become longer and more annoying to handle.
	// The default is 16 bytes, or 2^^128 possible combinations.
	ByteLength param.Field[int64] `json:"byteLength"`
	// Sets if key is enabled or disabled. Disabled keys are not valid.
	Enabled param.Field[bool] `json:"enabled"`
	// Environments allow you to divide your keyspace.
	//
	// Some applications like Stripe, Clerk, WorkOS and others have a concept of "live"
	// and "test" keys to give the developer a way to develop their own application
	// without the risk of modifying real world resources.
	//
	// When you set an environment, we will return it back to you when validating the
	// key, so you can handle it correctly.
	Environment param.Field[string] `json:"environment"`
	// You can auto expire keys by providing a unix timestamp in milliseconds. Once
	// Keys expire they will automatically be disabled and are no longer valid unless
	// you enable them again.
	Expires param.Field[int64] `json:"expires"`
	// Your user's Id. This will provide a link between Unkey and your customer record.
	// When validating a key, we will return this back to you, so you can clearly
	// identify your user from their api key.
	ExternalID param.Field[string] `json:"externalId"`
	// This is a place for dynamic meta data, anything that feels useful for you should
	// go here
	Meta param.Field[map[string]interface{}] `json:"meta"`
	// The name for your Key. This is not customer facing.
	Name param.Field[string] `json:"name"`
	// Deprecated, use `externalId`
	OwnerID param.Field[string] `json:"ownerId"`
	// A list of permissions that this key should have. If the permission does not
	// exist, an error is thrown
	Permissions param.Field[[]string] `json:"permissions"`
	// To make it easier for your users to understand which product an api key belongs
	// to, you can add prefix them.
	//
	// For example Stripe famously prefixes their customer ids with cus* or their api
	// keys with sk_live*.
	//
	// The underscore is automatically added if you are defining a prefix, for example:
	// "prefix": "abc" will result in a key like abc_xxxxxxxxx
	Prefix param.Field[string] `json:"prefix"`
	// Unkey comes with per-key fixed-window ratelimiting out of the box.
	Ratelimit param.Field[V1KeyCreateKeyNewParamsRatelimit] `json:"ratelimit"`
	// Unkey enables you to refill verifications for each key at regular intervals.
	Refill param.Field[V1KeyCreateKeyNewParamsRefill] `json:"refill"`
	// You can limit the number of requests a key can make. Once a key reaches 0
	// remaining requests, it will automatically be disabled and is no longer valid
	// unless you update it.
	Remaining param.Field[int64] `json:"remaining"`
	// A list of roles that this key should have. If the role does not exist, an error
	// is thrown
	Roles param.Field[[]string] `json:"roles"`
}

func (V1KeyCreateKeyNewParams) MarshalJSON

func (r V1KeyCreateKeyNewParams) MarshalJSON() (data []byte, err error)

type V1KeyCreateKeyNewParamsRatelimit

type V1KeyCreateKeyNewParamsRatelimit struct {
	// The total amount of requests in a given interval.
	Limit param.Field[int64] `json:"limit,required"`
	// Async will return a response immediately, lowering latency at the cost of
	// accuracy. Will be required soon.
	Async param.Field[bool] `json:"async"`
	// The window duration in milliseconds. Will be required soon.
	Duration param.Field[int64] `json:"duration"`
	// The refill timeframe, in milliseconds.
	RefillInterval param.Field[int64] `json:"refillInterval"`
	// How many tokens to refill during each refillInterval.
	RefillRate param.Field[int64] `json:"refillRate"`
	// Deprecated, used `async`. Fast ratelimiting doesn't add latency, while
	// consistent ratelimiting is more accurate.
	Type param.Field[V1KeyCreateKeyNewParamsRatelimitType] `json:"type"`
}

Unkey comes with per-key fixed-window ratelimiting out of the box.

func (V1KeyCreateKeyNewParamsRatelimit) MarshalJSON

func (r V1KeyCreateKeyNewParamsRatelimit) MarshalJSON() (data []byte, err error)

type V1KeyCreateKeyNewParamsRatelimitType

type V1KeyCreateKeyNewParamsRatelimitType string

Deprecated, used `async`. Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate.

const (
	V1KeyCreateKeyNewParamsRatelimitTypeFast       V1KeyCreateKeyNewParamsRatelimitType = "fast"
	V1KeyCreateKeyNewParamsRatelimitTypeConsistent V1KeyCreateKeyNewParamsRatelimitType = "consistent"
)

func (V1KeyCreateKeyNewParamsRatelimitType) IsKnown

type V1KeyCreateKeyNewParamsRefill

type V1KeyCreateKeyNewParamsRefill struct {
	// The number of verifications to refill for each occurrence is determined
	// individually for each key.
	Amount param.Field[int64] `json:"amount,required"`
	// Unkey will automatically refill verifications at the set interval.
	Interval param.Field[V1KeyCreateKeyNewParamsRefillInterval] `json:"interval,required"`
}

Unkey enables you to refill verifications for each key at regular intervals.

func (V1KeyCreateKeyNewParamsRefill) MarshalJSON

func (r V1KeyCreateKeyNewParamsRefill) MarshalJSON() (data []byte, err error)

type V1KeyCreateKeyNewParamsRefillInterval

type V1KeyCreateKeyNewParamsRefillInterval string

Unkey will automatically refill verifications at the set interval.

const (
	V1KeyCreateKeyNewParamsRefillIntervalDaily   V1KeyCreateKeyNewParamsRefillInterval = "daily"
	V1KeyCreateKeyNewParamsRefillIntervalMonthly V1KeyCreateKeyNewParamsRefillInterval = "monthly"
)

func (V1KeyCreateKeyNewParamsRefillInterval) IsKnown

type V1KeyCreateKeyNewResponse

type V1KeyCreateKeyNewResponse struct {
	// The newly created api key, do not store this on your own system but pass it
	// along to your user.
	Key string `json:"key,required"`
	// The id of the key. This is not a secret and can be stored as a reference if you
	// wish. You need the keyId to update or delete a key later.
	KeyID string                        `json:"keyId,required"`
	JSON  v1KeyCreateKeyNewResponseJSON `json:"-"`
}

func (*V1KeyCreateKeyNewResponse) UnmarshalJSON

func (r *V1KeyCreateKeyNewResponse) UnmarshalJSON(data []byte) (err error)

type V1KeyCreateKeyService

type V1KeyCreateKeyService struct {
	Options []option.RequestOption
}

V1KeyCreateKeyService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewV1KeyCreateKeyService method instead.

func NewV1KeyCreateKeyService

func NewV1KeyCreateKeyService(opts ...option.RequestOption) (r *V1KeyCreateKeyService)

NewV1KeyCreateKeyService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*V1KeyCreateKeyService) New

type V1KeyDeleteKeyNewParams

type V1KeyDeleteKeyNewParams struct {
	// The id of the key to revoke
	KeyID param.Field[string] `json:"keyId,required"`
}

func (V1KeyDeleteKeyNewParams) MarshalJSON

func (r V1KeyDeleteKeyNewParams) MarshalJSON() (data []byte, err error)

type V1KeyDeleteKeyNewResponse

type V1KeyDeleteKeyNewResponse = interface{}

type V1KeyDeleteKeyService

type V1KeyDeleteKeyService struct {
	Options []option.RequestOption
}

V1KeyDeleteKeyService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewV1KeyDeleteKeyService method instead.

func NewV1KeyDeleteKeyService

func NewV1KeyDeleteKeyService(opts ...option.RequestOption) (r *V1KeyDeleteKeyService)

NewV1KeyDeleteKeyService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*V1KeyDeleteKeyService) New

type V1KeyGetKeyGetParams

type V1KeyGetKeyGetParams struct {
	// The id of the key to fetch
	KeyID param.Field[string] `query:"keyId,required"`
	// Decrypt and display the raw key. Only possible if the key was encrypted when
	// generated.
	Decrypt param.Field[bool] `query:"decrypt"`
}

func (V1KeyGetKeyGetParams) URLQuery

func (r V1KeyGetKeyGetParams) URLQuery() (v url.Values)

URLQuery serializes V1KeyGetKeyGetParams's query parameters as `url.Values`.

type V1KeyGetKeyGetResponse

type V1KeyGetKeyGetResponse struct {
	// The id of the key
	ID string `json:"id,required"`
	// The unix timestamp in milliseconds when the key was created
	CreatedAt int64 `json:"createdAt,required"`
	// The first few characters of the key to visually identify it
	Start string `json:"start,required"`
	// The id of the workspace that owns the key
	WorkspaceID string `json:"workspaceId,required"`
	// The id of the api that this key is for
	APIID string `json:"apiId"`
	// The unix timestamp in milliseconds when the key was deleted. We don't delete the
	// key outright, you can restore it later.
	DeletedAt int64 `json:"deletedAt"`
	// Sets if key is enabled or disabled. Disabled keys are not valid.
	Enabled bool `json:"enabled"`
	// The unix timestamp in milliseconds when the key will expire. If this field is
	// null or undefined, the key is not expiring.
	Expires int64 `json:"expires"`
	// The identity of the key
	Identity V1KeyGetKeyGetResponseIdentity `json:"identity"`
	// Any additional metadata you want to store with the key
	Meta map[string]interface{} `json:"meta"`
	// The name of the key, give keys a name to easily identify their purpose
	Name string `json:"name"`
	// The id of the tenant associated with this key. Use whatever reference you have
	// in your system to identify the tenant. When verifying the key, we will send this
	// field back to you, so you know who is accessing your API.
	OwnerID string `json:"ownerId"`
	// All permissions this key has
	Permissions []string `json:"permissions"`
	// The key in plaintext
	Plaintext string `json:"plaintext"`
	// Unkey comes with per-key ratelimiting out of the box.
	Ratelimit V1KeyGetKeyGetResponseRatelimit `json:"ratelimit"`
	// Unkey allows you to refill remaining verifications on a key on a regular
	// interval.
	Refill V1KeyGetKeyGetResponseRefill `json:"refill"`
	// The number of requests that can be made with this key before it becomes invalid.
	// If this field is null or undefined, the key has no request limit.
	Remaining int64 `json:"remaining"`
	// All roles this key belongs to
	Roles []string `json:"roles"`
	// The unix timestamp in milliseconds when the key was last updated
	UpdatedAt int64                      `json:"updatedAt"`
	JSON      v1KeyGetKeyGetResponseJSON `json:"-"`
}

func (*V1KeyGetKeyGetResponse) UnmarshalJSON

func (r *V1KeyGetKeyGetResponse) UnmarshalJSON(data []byte) (err error)

type V1KeyGetKeyGetResponseIdentity

type V1KeyGetKeyGetResponseIdentity struct {
	// The id of the identity
	ID string `json:"id,required"`
	// The external id of the identity
	ExternalID string `json:"externalId,required"`
	// Any additional metadata attached to the identity
	Meta map[string]interface{}             `json:"meta"`
	JSON v1KeyGetKeyGetResponseIdentityJSON `json:"-"`
}

The identity of the key

func (*V1KeyGetKeyGetResponseIdentity) UnmarshalJSON

func (r *V1KeyGetKeyGetResponseIdentity) UnmarshalJSON(data []byte) (err error)

type V1KeyGetKeyGetResponseRatelimit

type V1KeyGetKeyGetResponseRatelimit struct {
	Async bool `json:"async,required"`
	// The duration of the ratelimit window, in milliseconds.
	Duration int64 `json:"duration,required"`
	// The total amount of burstable requests.
	Limit int64 `json:"limit,required"`
	// Determines the speed at which tokens are refilled, in milliseconds.
	RefillInterval int64 `json:"refillInterval"`
	// How many tokens to refill during each refillInterval.
	RefillRate int64 `json:"refillRate"`
	// Fast ratelimiting doesn't add latency, while consistent ratelimiting is more
	// accurate.
	Type V1KeyGetKeyGetResponseRatelimitType `json:"type"`
	JSON v1KeyGetKeyGetResponseRatelimitJSON `json:"-"`
}

Unkey comes with per-key ratelimiting out of the box.

func (*V1KeyGetKeyGetResponseRatelimit) UnmarshalJSON

func (r *V1KeyGetKeyGetResponseRatelimit) UnmarshalJSON(data []byte) (err error)

type V1KeyGetKeyGetResponseRatelimitType

type V1KeyGetKeyGetResponseRatelimitType string

Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate.

const (
	V1KeyGetKeyGetResponseRatelimitTypeFast       V1KeyGetKeyGetResponseRatelimitType = "fast"
	V1KeyGetKeyGetResponseRatelimitTypeConsistent V1KeyGetKeyGetResponseRatelimitType = "consistent"
)

func (V1KeyGetKeyGetResponseRatelimitType) IsKnown

type V1KeyGetKeyGetResponseRefill

type V1KeyGetKeyGetResponseRefill struct {
	// Resets `remaining` to this value every interval.
	Amount int64 `json:"amount,required"`
	// Determines the rate at which verifications will be refilled.
	Interval V1KeyGetKeyGetResponseRefillInterval `json:"interval,required"`
	// The unix timestamp in miliseconds when the key was last refilled.
	LastRefillAt int64                            `json:"lastRefillAt"`
	JSON         v1KeyGetKeyGetResponseRefillJSON `json:"-"`
}

Unkey allows you to refill remaining verifications on a key on a regular interval.

func (*V1KeyGetKeyGetResponseRefill) UnmarshalJSON

func (r *V1KeyGetKeyGetResponseRefill) UnmarshalJSON(data []byte) (err error)

type V1KeyGetKeyGetResponseRefillInterval

type V1KeyGetKeyGetResponseRefillInterval string

Determines the rate at which verifications will be refilled.

const (
	V1KeyGetKeyGetResponseRefillIntervalDaily   V1KeyGetKeyGetResponseRefillInterval = "daily"
	V1KeyGetKeyGetResponseRefillIntervalMonthly V1KeyGetKeyGetResponseRefillInterval = "monthly"
)

func (V1KeyGetKeyGetResponseRefillInterval) IsKnown

type V1KeyGetKeyService

type V1KeyGetKeyService struct {
	Options []option.RequestOption
}

V1KeyGetKeyService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewV1KeyGetKeyService method instead.

func NewV1KeyGetKeyService

func NewV1KeyGetKeyService(opts ...option.RequestOption) (r *V1KeyGetKeyService)

NewV1KeyGetKeyService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*V1KeyGetKeyService) Get

type V1KeyGetVerificationListParams

type V1KeyGetVerificationListParams struct {
	// The end of the period to fetch usage for as unix milliseconds timestamp
	End param.Field[int64] `query:"end"`
	// The granularity of the usage data to fetch, currently only `day` is supported
	Granularity param.Field[V1KeyGetVerificationListParamsGranularity] `query:"granularity"`
	// The id of the key to fetch, either `keyId` or `ownerId` must be provided
	KeyID param.Field[string] `query:"keyId"`
	// The owner id to fetch keys for, either `keyId` or `ownerId` must be provided
	OwnerID param.Field[string] `query:"ownerId"`
	// The start of the period to fetch usage for as unix milliseconds timestamp
	Start param.Field[int64] `query:"start"`
}

func (V1KeyGetVerificationListParams) URLQuery

func (r V1KeyGetVerificationListParams) URLQuery() (v url.Values)

URLQuery serializes V1KeyGetVerificationListParams's query parameters as `url.Values`.

type V1KeyGetVerificationListParamsGranularity

type V1KeyGetVerificationListParamsGranularity string

The granularity of the usage data to fetch, currently only `day` is supported

const (
	V1KeyGetVerificationListParamsGranularityDay V1KeyGetVerificationListParamsGranularity = "day"
)

func (V1KeyGetVerificationListParamsGranularity) IsKnown

type V1KeyGetVerificationListResponse

type V1KeyGetVerificationListResponse struct {
	Verifications []V1KeyGetVerificationListResponseVerification `json:"verifications,required"`
	JSON          v1KeyGetVerificationListResponseJSON           `json:"-"`
}

func (*V1KeyGetVerificationListResponse) UnmarshalJSON

func (r *V1KeyGetVerificationListResponse) UnmarshalJSON(data []byte) (err error)

type V1KeyGetVerificationListResponseVerification

type V1KeyGetVerificationListResponseVerification struct {
	// The number of requests that were rate limited
	RateLimited int64 `json:"rateLimited,required"`
	// The number of successful requests
	Success int64 `json:"success,required"`
	// The timestamp of the usage data
	Time int64 `json:"time,required"`
	// The number of requests that exceeded the usage limit
	UsageExceeded int64                                            `json:"usageExceeded,required"`
	JSON          v1KeyGetVerificationListResponseVerificationJSON `json:"-"`
}

func (*V1KeyGetVerificationListResponseVerification) UnmarshalJSON

func (r *V1KeyGetVerificationListResponseVerification) UnmarshalJSON(data []byte) (err error)

type V1KeyGetVerificationService

type V1KeyGetVerificationService struct {
	Options []option.RequestOption
}

V1KeyGetVerificationService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewV1KeyGetVerificationService method instead.

func NewV1KeyGetVerificationService

func NewV1KeyGetVerificationService(opts ...option.RequestOption) (r *V1KeyGetVerificationService)

NewV1KeyGetVerificationService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*V1KeyGetVerificationService) List

type V1KeyService

type V1KeyService struct {
	Options          []option.RequestOption
	GetKey           *V1KeyGetKeyService
	DeleteKey        *V1KeyDeleteKeyService
	CreateKey        *V1KeyCreateKeyService
	VerifyKey        *V1KeyVerifyKeyService
	UpdateKey        *V1KeyUpdateKeyService
	UpdateRemaining  *V1KeyUpdateRemainingService
	GetVerifications *V1KeyGetVerificationService
}

V1KeyService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewV1KeyService method instead.

func NewV1KeyService

func NewV1KeyService(opts ...option.RequestOption) (r *V1KeyService)

NewV1KeyService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

type V1KeyUpdateKeyNewParams

type V1KeyUpdateKeyNewParams struct {
	// The id of the key you want to modify
	KeyID param.Field[string] `json:"keyId,required"`
	// Set if key is enabled or disabled. If disabled, the key cannot be used to
	// verify.
	Enabled param.Field[bool] `json:"enabled"`
	// The unix timestamp in milliseconds when the key will expire. If this field is
	// null or undefined, the key is not expiring.
	Expires param.Field[int64] `json:"expires"`
	// Any additional metadata you want to store with the key
	Meta param.Field[map[string]interface{}] `json:"meta"`
	// The name of the key
	Name param.Field[string] `json:"name"`
	// The id of the tenant associated with this key. Use whatever reference you have
	// in your system to identify the tenant. When verifying the key, we will send this
	// field back to you, so you know who is accessing your API.
	OwnerID param.Field[string] `json:"ownerId"`
	// The permissions you want to set for this key. This overwrites all existing
	// permissions. Setting permissions requires the `rbac.*.add_permission_to_key`
	// permission.
	Permissions param.Field[[]V1KeyUpdateKeyNewParamsPermission] `json:"permissions"`
	// Unkey comes with per-key ratelimiting out of the box. Set `null` to disable.
	Ratelimit param.Field[V1KeyUpdateKeyNewParamsRatelimit] `json:"ratelimit"`
	// Unkey enables you to refill verifications for each key at regular intervals.
	Refill param.Field[V1KeyUpdateKeyNewParamsRefill] `json:"refill"`
	// The number of requests that can be made with this key before it becomes invalid.
	// Set `null` to disable.
	Remaining param.Field[int64] `json:"remaining"`
	// The roles you want to set for this key. This overwrites all existing roles.
	// Setting roles requires the `rbac.*.add_role_to_key` permission.
	Roles param.Field[[]V1KeyUpdateKeyNewParamsRole] `json:"roles"`
}

func (V1KeyUpdateKeyNewParams) MarshalJSON

func (r V1KeyUpdateKeyNewParams) MarshalJSON() (data []byte, err error)

type V1KeyUpdateKeyNewParamsPermission

type V1KeyUpdateKeyNewParamsPermission struct {
	// The id of the permission. Provide either `id` or `name`. If both are provided
	// `id` is used.
	ID param.Field[string] `json:"id"`
	// Set to true to automatically create the permissions they do not exist yet. Only
	// works when specifying `name`. Autocreating permissions requires your root key to
	// have the `rbac.*.create_permission` permission, otherwise the request will get
	// rejected
	Create param.Field[bool] `json:"create"`
	// Identify the permission via its name. Provide either `id` or `name`. If both are
	// provided `id` is used.
	Name param.Field[string] `json:"name"`
}

func (V1KeyUpdateKeyNewParamsPermission) MarshalJSON

func (r V1KeyUpdateKeyNewParamsPermission) MarshalJSON() (data []byte, err error)

type V1KeyUpdateKeyNewParamsRatelimit

type V1KeyUpdateKeyNewParamsRatelimit struct {
	// The total amount of requests allowed in a single window.
	Limit param.Field[int64] `json:"limit,required"`
	// Asnyc ratelimiting doesn't add latency, while sync ratelimiting is slightly more
	// accurate.
	Async param.Field[bool] `json:"async"`
	// The duration of each ratelimit window, in milliseconds. This field will become
	// required in a future version.
	Duration param.Field[int64] `json:"duration"`
	// Determines the speed at which tokens are refilled, in milliseconds. Deprecated,
	// use 'duration'
	RefillInterval param.Field[int64] `json:"refillInterval"`
	// How many tokens to refill during each refillInterval. Deprecated, use 'limit'
	// instead.
	RefillRate param.Field[int64] `json:"refillRate"`
	// Fast ratelimiting doesn't add latency, while consistent ratelimiting is more
	// accurate. Deprecated, use 'async' instead
	Type param.Field[V1KeyUpdateKeyNewParamsRatelimitType] `json:"type"`
}

Unkey comes with per-key ratelimiting out of the box. Set `null` to disable.

func (V1KeyUpdateKeyNewParamsRatelimit) MarshalJSON

func (r V1KeyUpdateKeyNewParamsRatelimit) MarshalJSON() (data []byte, err error)

type V1KeyUpdateKeyNewParamsRatelimitType

type V1KeyUpdateKeyNewParamsRatelimitType string

Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate. Deprecated, use 'async' instead

const (
	V1KeyUpdateKeyNewParamsRatelimitTypeFast       V1KeyUpdateKeyNewParamsRatelimitType = "fast"
	V1KeyUpdateKeyNewParamsRatelimitTypeConsistent V1KeyUpdateKeyNewParamsRatelimitType = "consistent"
)

func (V1KeyUpdateKeyNewParamsRatelimitType) IsKnown

type V1KeyUpdateKeyNewParamsRefill

type V1KeyUpdateKeyNewParamsRefill struct {
	// The amount of verifications to refill for each occurrence is determined
	// individually for each key.
	Amount param.Field[int64] `json:"amount,required"`
	// Unkey will automatically refill verifications at the set interval. If null is
	// used the refill functionality will be removed from the key.
	Interval param.Field[V1KeyUpdateKeyNewParamsRefillInterval] `json:"interval,required"`
}

Unkey enables you to refill verifications for each key at regular intervals.

func (V1KeyUpdateKeyNewParamsRefill) MarshalJSON

func (r V1KeyUpdateKeyNewParamsRefill) MarshalJSON() (data []byte, err error)

type V1KeyUpdateKeyNewParamsRefillInterval

type V1KeyUpdateKeyNewParamsRefillInterval string

Unkey will automatically refill verifications at the set interval. If null is used the refill functionality will be removed from the key.

const (
	V1KeyUpdateKeyNewParamsRefillIntervalDaily   V1KeyUpdateKeyNewParamsRefillInterval = "daily"
	V1KeyUpdateKeyNewParamsRefillIntervalMonthly V1KeyUpdateKeyNewParamsRefillInterval = "monthly"
)

func (V1KeyUpdateKeyNewParamsRefillInterval) IsKnown

type V1KeyUpdateKeyNewParamsRole

type V1KeyUpdateKeyNewParamsRole struct {
	// The id of the role. Provide either `id` or `name`. If both are provided `id` is
	// used.
	ID param.Field[string] `json:"id"`
	// Set to true to automatically create the permissions they do not exist yet. Only
	// works when specifying `name`. Autocreating roles requires your root key to have
	// the `rbac.*.create_role` permission, otherwise the request will get rejected
	Create param.Field[bool] `json:"create"`
	// Identify the role via its name. Provide either `id` or `name`. If both are
	// provided `id` is used.
	Name param.Field[string] `json:"name"`
}

func (V1KeyUpdateKeyNewParamsRole) MarshalJSON

func (r V1KeyUpdateKeyNewParamsRole) MarshalJSON() (data []byte, err error)

type V1KeyUpdateKeyNewResponse

type V1KeyUpdateKeyNewResponse = interface{}

type V1KeyUpdateKeyService

type V1KeyUpdateKeyService struct {
	Options []option.RequestOption
}

V1KeyUpdateKeyService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewV1KeyUpdateKeyService method instead.

func NewV1KeyUpdateKeyService

func NewV1KeyUpdateKeyService(opts ...option.RequestOption) (r *V1KeyUpdateKeyService)

NewV1KeyUpdateKeyService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*V1KeyUpdateKeyService) New

type V1KeyUpdateRemainingNewParams

type V1KeyUpdateRemainingNewParams struct {
	// The id of the key you want to modify
	KeyID param.Field[string] `json:"keyId,required"`
	// The operation you want to perform on the remaining count
	Op param.Field[V1KeyUpdateRemainingNewParamsOp] `json:"op,required"`
	// The value you want to set, add or subtract the remaining count by
	Value param.Field[int64] `json:"value,required"`
}

func (V1KeyUpdateRemainingNewParams) MarshalJSON

func (r V1KeyUpdateRemainingNewParams) MarshalJSON() (data []byte, err error)

type V1KeyUpdateRemainingNewParamsOp

type V1KeyUpdateRemainingNewParamsOp string

The operation you want to perform on the remaining count

const (
	V1KeyUpdateRemainingNewParamsOpIncrement V1KeyUpdateRemainingNewParamsOp = "increment"
	V1KeyUpdateRemainingNewParamsOpDecrement V1KeyUpdateRemainingNewParamsOp = "decrement"
	V1KeyUpdateRemainingNewParamsOpSet       V1KeyUpdateRemainingNewParamsOp = "set"
)

func (V1KeyUpdateRemainingNewParamsOp) IsKnown

type V1KeyUpdateRemainingNewResponse

type V1KeyUpdateRemainingNewResponse struct {
	// The number of remaining requests for this key after updating it. `null` means
	// unlimited.
	Remaining int64                               `json:"remaining,required,nullable"`
	JSON      v1KeyUpdateRemainingNewResponseJSON `json:"-"`
}

func (*V1KeyUpdateRemainingNewResponse) UnmarshalJSON

func (r *V1KeyUpdateRemainingNewResponse) UnmarshalJSON(data []byte) (err error)

type V1KeyUpdateRemainingService

type V1KeyUpdateRemainingService struct {
	Options []option.RequestOption
}

V1KeyUpdateRemainingService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewV1KeyUpdateRemainingService method instead.

func NewV1KeyUpdateRemainingService

func NewV1KeyUpdateRemainingService(opts ...option.RequestOption) (r *V1KeyUpdateRemainingService)

NewV1KeyUpdateRemainingService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*V1KeyUpdateRemainingService) New

type V1KeyVerifyKeyNewParams

type V1KeyVerifyKeyNewParams struct {
	// The key to verify
	Key param.Field[string] `json:"key,required"`
	// The id of the api where the key belongs to. This is optional for now but will be
	// required soon. The key will be verified against the api's configuration. If the
	// key does not belong to the api, the verification will fail.
	APIID param.Field[string] `json:"apiId"`
	// Perform RBAC checks
	Authorization param.Field[V1KeyVerifyKeyNewParamsAuthorization] `json:"authorization"`
	// Use 'ratelimits' with `[{ name: "default", cost: 2}]`
	Ratelimit param.Field[V1KeyVerifyKeyNewParamsRatelimit] `json:"ratelimit"`
	// You can check against multiple ratelimits when verifying a key. Let's say you
	// are building an app that uses AI under the hood and you want to limit your
	// customers to 500 requests per hour, but also ensure they use up less than 20k
	// tokens per day.
	Ratelimits param.Field[[]V1KeyVerifyKeyNewParamsRatelimit] `json:"ratelimits"`
}

func (V1KeyVerifyKeyNewParams) MarshalJSON

func (r V1KeyVerifyKeyNewParams) MarshalJSON() (data []byte, err error)

type V1KeyVerifyKeyNewParamsAuthorization

type V1KeyVerifyKeyNewParamsAuthorization struct {
	// A query for which permissions you require
	Permissions param.Field[V1KeyVerifyKeyNewParamsAuthorizationPermissionsUnion] `json:"permissions"`
}

Perform RBAC checks

func (V1KeyVerifyKeyNewParamsAuthorization) MarshalJSON

func (r V1KeyVerifyKeyNewParamsAuthorization) MarshalJSON() (data []byte, err error)

type V1KeyVerifyKeyNewParamsAuthorizationPermissions

type V1KeyVerifyKeyNewParamsAuthorizationPermissions struct {
	And param.Field[interface{}] `json:"and,required"`
	Or  param.Field[interface{}] `json:"or,required"`
}

A query for which permissions you require

func (V1KeyVerifyKeyNewParamsAuthorizationPermissions) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissions) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissions) MarshalJSON

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissions) MarshalJSON() (data []byte, err error)

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAnd

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAnd struct {
	And param.Field[[]V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndUnion] `json:"and,required"`
}

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAnd) MarshalJSON

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsAnd) MarshalJSON() (data []byte, err error)

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAnd

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAnd struct {
	And param.Field[interface{}] `json:"and,required"`
	Or  param.Field[interface{}] `json:"or,required"`
}

A query for which permissions you require

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAnd) MarshalJSON

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndAnd

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndAnd struct {
	And param.Field[[]interface{}] `json:"and,required"`
}

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndAnd) MarshalJSON

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOr

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOr struct {
	Or param.Field[[]V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrUnion] `json:"or,required"`
}

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOr) MarshalJSON

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOr

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOr struct {
	And param.Field[interface{}] `json:"and,required"`
	Or  param.Field[interface{}] `json:"or,required"`
}

A query for which permissions you require

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOr) MarshalJSON

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrAnd

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrAnd struct {
	And param.Field[[]interface{}] `json:"and,required"`
}

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrAnd) MarshalJSON

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrOr

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrOr struct {
	Or param.Field[[]interface{}] `json:"or,required"`
}

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrOr) MarshalJSON

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrUnion

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrUnion interface {
	ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrUnion()
}

A query for which permissions you require

Satisfied by [shared.UnionString], V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrAnd, V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOrOr, V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOrOr.

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndUnion

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndUnion interface {
	ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndUnion()
}

A query for which permissions you require

Satisfied by [shared.UnionString], V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndAnd, V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAndOr, V1KeyVerifyKeyNewParamsAuthorizationPermissionsAndAnd.

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOr

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOr struct {
	Or param.Field[[]V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrUnion] `json:"or,required"`
}

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOr) MarshalJSON

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsOr) MarshalJSON() (data []byte, err error)

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOr

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOr struct {
	And param.Field[interface{}] `json:"and,required"`
	Or  param.Field[interface{}] `json:"or,required"`
}

A query for which permissions you require

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOr) MarshalJSON

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOr) MarshalJSON() (data []byte, err error)

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAnd

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAnd struct {
	And param.Field[[]V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndUnion] `json:"and,required"`
}

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAnd) MarshalJSON

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAnd

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAnd struct {
	And param.Field[interface{}] `json:"and,required"`
	Or  param.Field[interface{}] `json:"or,required"`
}

A query for which permissions you require

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAnd) MarshalJSON

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndAnd

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndAnd struct {
	And param.Field[[]interface{}] `json:"and,required"`
}

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndAnd) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndAnd) MarshalJSON

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndOr

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndOr struct {
	Or param.Field[[]interface{}] `json:"or,required"`
}

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndOr) MarshalJSON

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndUnion

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndUnion interface {
	ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndUnion()
}

A query for which permissions you require

Satisfied by [shared.UnionString], V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndAnd, V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAndOr, V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAndAnd.

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrOr

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrOr struct {
	Or param.Field[[]interface{}] `json:"or,required"`
}

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrUnion

func (r V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrOr) ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrUnion()

func (V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrOr) MarshalJSON

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrUnion

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrUnion interface {
	ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrUnion()
}

A query for which permissions you require

Satisfied by [shared.UnionString], V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrAnd, V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOrOr, V1KeyVerifyKeyNewParamsAuthorizationPermissionsOrOr.

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsUnion

type V1KeyVerifyKeyNewParamsAuthorizationPermissionsUnion interface {
	ImplementsV1KeyVerifyKeyNewParamsAuthorizationPermissionsUnion()
}

A query for which permissions you require

Satisfied by [shared.UnionString], V1KeyVerifyKeyNewParamsAuthorizationPermissionsAnd, V1KeyVerifyKeyNewParamsAuthorizationPermissionsOr, V1KeyVerifyKeyNewParamsAuthorizationPermissions.

type V1KeyVerifyKeyNewParamsRatelimit

type V1KeyVerifyKeyNewParamsRatelimit struct {
	// Override how many tokens are deducted during the ratelimit operation.
	Cost param.Field[int64] `json:"cost"`
}

Use 'ratelimits' with `[{ name: "default", cost: 2}]`

func (V1KeyVerifyKeyNewParamsRatelimit) MarshalJSON

func (r V1KeyVerifyKeyNewParamsRatelimit) MarshalJSON() (data []byte, err error)

type V1KeyVerifyKeyService

type V1KeyVerifyKeyService struct {
	Options []option.RequestOption
}

V1KeyVerifyKeyService contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewV1KeyVerifyKeyService method instead.

func NewV1KeyVerifyKeyService

func NewV1KeyVerifyKeyService(opts ...option.RequestOption) (r *V1KeyVerifyKeyService)

NewV1KeyVerifyKeyService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*V1KeyVerifyKeyService) New

type V1KeysVerifyKeyResponse

type V1KeysVerifyKeyResponse struct {
	// A machine readable code why the key is not valid. Possible values are:
	//
	//   - VALID: the key is valid and you should proceed
	//   - NOT_FOUND: the key does not exist or has expired
	//   - FORBIDDEN: the key is not allowed to access the api
	//   - USAGE_EXCEEDED: the key has exceeded its request limit
	//   - RATE_LIMITED: the key has been ratelimited
	//   - UNAUTHORIZED: the key is not authorized
	//   - DISABLED: the key is disabled
	//   - INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform
	//     this action
	//   - EXPIRED: The key was only valid for a certain time and has expired.
	Code V1KeysVerifyKeyResponseCode `json:"code,required"`
	// Whether the key is valid or not. A key could be invalid for a number of reasons,
	// for example if it has expired, has no more verifications left or if it has been
	// deleted.
	Valid bool `json:"valid,required"`
	// Sets the key to be enabled or disabled. Disabled keys will not verify.
	Enabled bool `json:"enabled"`
	// The environment of the key, this is what what you set when you crated the key
	Environment string `json:"environment"`
	// The unix timestamp in milliseconds when the key will expire. If this field is
	// null or undefined, the key is not expiring.
	Expires int64 `json:"expires"`
	// The associated identity of this key.
	Identity V1KeysVerifyKeyResponseIdentity `json:"identity"`
	// The id of the key
	KeyID string `json:"keyId"`
	// Any additional metadata you want to store with the key
	Meta map[string]interface{} `json:"meta"`
	// The name of the key, give keys a name to easily identifiy their purpose
	Name string `json:"name"`
	// The id of the tenant associated with this key. Use whatever reference you have
	// in your system to identify the tenant. When verifying the key, we will send this
	// field back to you, so you know who is accessing your API.
	OwnerID string `json:"ownerId"`
	// A list of all the permissions this key is connected to.
	Permissions []string `json:"permissions"`
	// The ratelimit configuration for this key. If this field is null or undefined,
	// the key has no ratelimit.
	Ratelimit V1KeysVerifyKeyResponseRatelimit `json:"ratelimit"`
	// The number of requests that can be made with this key before it becomes invalid.
	// If this field is null or undefined, the key has no request limit.
	Remaining int64                       `json:"remaining"`
	JSON      v1KeysVerifyKeyResponseJSON `json:"-"`
}

func (*V1KeysVerifyKeyResponse) UnmarshalJSON

func (r *V1KeysVerifyKeyResponse) UnmarshalJSON(data []byte) (err error)

type V1KeysVerifyKeyResponseCode

type V1KeysVerifyKeyResponseCode string

A machine readable code why the key is not valid. Possible values are:

  • VALID: the key is valid and you should proceed
  • NOT_FOUND: the key does not exist or has expired
  • FORBIDDEN: the key is not allowed to access the api
  • USAGE_EXCEEDED: the key has exceeded its request limit
  • RATE_LIMITED: the key has been ratelimited
  • UNAUTHORIZED: the key is not authorized
  • DISABLED: the key is disabled
  • INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform this action
  • EXPIRED: The key was only valid for a certain time and has expired.
const (
	V1KeysVerifyKeyResponseCodeValid                   V1KeysVerifyKeyResponseCode = "VALID"
	V1KeysVerifyKeyResponseCodeNotFound                V1KeysVerifyKeyResponseCode = "NOT_FOUND"
	V1KeysVerifyKeyResponseCodeForbidden               V1KeysVerifyKeyResponseCode = "FORBIDDEN"
	V1KeysVerifyKeyResponseCodeUsageExceeded           V1KeysVerifyKeyResponseCode = "USAGE_EXCEEDED"
	V1KeysVerifyKeyResponseCodeRateLimited             V1KeysVerifyKeyResponseCode = "RATE_LIMITED"
	V1KeysVerifyKeyResponseCodeUnauthorized            V1KeysVerifyKeyResponseCode = "UNAUTHORIZED"
	V1KeysVerifyKeyResponseCodeDisabled                V1KeysVerifyKeyResponseCode = "DISABLED"
	V1KeysVerifyKeyResponseCodeInsufficientPermissions V1KeysVerifyKeyResponseCode = "INSUFFICIENT_PERMISSIONS"
	V1KeysVerifyKeyResponseCodeExpired                 V1KeysVerifyKeyResponseCode = "EXPIRED"
)

func (V1KeysVerifyKeyResponseCode) IsKnown

func (r V1KeysVerifyKeyResponseCode) IsKnown() bool

type V1KeysVerifyKeyResponseIdentity

type V1KeysVerifyKeyResponseIdentity struct {
	ID         string                              `json:"id,required"`
	ExternalID string                              `json:"externalId,required"`
	Meta       map[string]interface{}              `json:"meta,required"`
	JSON       v1KeysVerifyKeyResponseIdentityJSON `json:"-"`
}

The associated identity of this key.

func (*V1KeysVerifyKeyResponseIdentity) UnmarshalJSON

func (r *V1KeysVerifyKeyResponseIdentity) UnmarshalJSON(data []byte) (err error)

type V1KeysVerifyKeyResponseRatelimit

type V1KeysVerifyKeyResponseRatelimit struct {
	// Maximum number of requests that can be made inside a window
	Limit int64 `json:"limit,required"`
	// Remaining requests after this verification
	Remaining int64 `json:"remaining,required"`
	// Unix timestamp in milliseconds when the ratelimit will reset
	Reset int64                                `json:"reset,required"`
	JSON  v1KeysVerifyKeyResponseRatelimitJSON `json:"-"`
}

The ratelimit configuration for this key. If this field is null or undefined, the key has no ratelimit.

func (*V1KeysVerifyKeyResponseRatelimit) UnmarshalJSON

func (r *V1KeysVerifyKeyResponseRatelimit) UnmarshalJSON(data []byte) (err error)

type V1LivenessResponse

type V1LivenessResponse struct {
	Services V1LivenessResponseServices `json:"services,required"`
	// The status of the server
	Status string                 `json:"status,required"`
	JSON   v1LivenessResponseJSON `json:"-"`
}

func (*V1LivenessResponse) UnmarshalJSON

func (r *V1LivenessResponse) UnmarshalJSON(data []byte) (err error)

type V1LivenessResponseServices

type V1LivenessResponseServices struct {
	// The name of the connected analytics service
	Analytics string `json:"analytics,required"`
	// The name of the connected logger service
	Logger string `json:"logger,required"`
	// The name of the connected metrics service
	Metrics string `json:"metrics,required"`
	// The name of the connected ratelimit service
	Ratelimit string `json:"ratelimit,required"`
	// The name of the connected usagelimit service
	Usagelimit string                         `json:"usagelimit,required"`
	JSON       v1LivenessResponseServicesJSON `json:"-"`
}

func (*V1LivenessResponseServices) UnmarshalJSON

func (r *V1LivenessResponseServices) UnmarshalJSON(data []byte) (err error)

type V1Service

type V1Service struct {
	Options []option.RequestOption
	Keys    *V1KeyService
	APIs    *V1APIService
}

V1Service contains methods and other services that help with interacting with the bannerify API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewV1Service method instead.

func NewV1Service

func NewV1Service(opts ...option.RequestOption) (r *V1Service)

NewV1Service generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*V1Service) Liveness

func (r *V1Service) Liveness(ctx context.Context, opts ...option.RequestOption) (res *V1LivenessResponse, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL