Categorygithub.com/Kong/sdk-konnect-go
modulepackage
0.1.15
Repository: https://github.com/kong/sdk-konnect-go.git
Documentation: pkg.go.dev

# README

sdk-konnect-go

This is a prototype and should not be used. See CONTRIBUTING.md for information on how this SDK is generated.

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.

By Default, an API error will return sdkerrors.SDKError. When custom error responses are specified for an operation, the SDK may also return their associated error. You can refer to respective Errors tables in SDK docs for more details on possible error types for each operation.

For example, the ListControlPlanes function may return the following errors:

Error TypeStatus CodeContent Type
sdkerrors.BadRequestError400application/problem+json
sdkerrors.UnauthorizedError401application/problem+json
sdkerrors.ForbiddenError403application/problem+json
sdkerrors.ServiceUnavailable503application/problem+json
sdkerrors.SDKError4XX, 5XX*/*

Example

package main

import (
	"context"
	"errors"
	sdkkonnectgo "github.com/Kong/sdk-konnect-go"
	"github.com/Kong/sdk-konnect-go/models/components"
	"github.com/Kong/sdk-konnect-go/models/operations"
	"github.com/Kong/sdk-konnect-go/models/sdkerrors"
	"log"
)

func main() {
	ctx := context.Background()

	s := sdkkonnectgo.New(
		sdkkonnectgo.WithSecurity(components.Security{
			PersonalAccessToken: sdkkonnectgo.String("<YOUR_BEARER_TOKEN_HERE>"),
		}),
	)

	res, err := s.ControlPlanes.ListControlPlanes(ctx, operations.ListControlPlanesRequest{
		PageSize:   sdkkonnectgo.Int64(10),
		PageNumber: sdkkonnectgo.Int64(1),
		Filter: &components.ControlPlaneFilterParameters{
			CloudGateway: sdkkonnectgo.Bool(true),
		},
		Labels: sdkkonnectgo.String("key:value,existCheck"),
		Sort:   sdkkonnectgo.String("name,created_at desc"),
	})
	if err != nil {

		var e *sdkerrors.BadRequestError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *sdkerrors.UnauthorizedError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *sdkerrors.ForbiddenError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *sdkerrors.ServiceUnavailable
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *sdkerrors.SDKError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}
	}
}

Server Selection

Select Server by Index

You can override the default server globally using the WithServerIndex(serverIndex int) option when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

#Server
0https://global.api.konghq.com
1https://us.api.konghq.com
2https://eu.api.konghq.com
3https://au.api.konghq.com

Example

package main

import (
	"context"
	sdkkonnectgo "github.com/Kong/sdk-konnect-go"
	"github.com/Kong/sdk-konnect-go/models/components"
	"github.com/Kong/sdk-konnect-go/models/operations"
	"log"
)

func main() {
	ctx := context.Background()

	s := sdkkonnectgo.New(
		sdkkonnectgo.WithServerIndex(3),
		sdkkonnectgo.WithSecurity(components.Security{
			PersonalAccessToken: sdkkonnectgo.String("<YOUR_BEARER_TOKEN_HERE>"),
		}),
	)

	res, err := s.ControlPlanes.ListControlPlanes(ctx, operations.ListControlPlanesRequest{
		PageSize:   sdkkonnectgo.Int64(10),
		PageNumber: sdkkonnectgo.Int64(1),
		Filter: &components.ControlPlaneFilterParameters{
			CloudGateway: sdkkonnectgo.Bool(true),
		},
		Labels: sdkkonnectgo.String("key:value,existCheck"),
		Sort:   sdkkonnectgo.String("name,created_at desc"),
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.ListControlPlanesResponse != nil {
		// handle response
	}
}

Override Server URL Per-Client

The default server can also be overridden globally using the WithServerURL(serverURL string) option when initializing the SDK client instance. For example:

package main

import (
	"context"
	sdkkonnectgo "github.com/Kong/sdk-konnect-go"
	"github.com/Kong/sdk-konnect-go/models/components"
	"github.com/Kong/sdk-konnect-go/models/operations"
	"log"
)

func main() {
	ctx := context.Background()

	s := sdkkonnectgo.New(
		sdkkonnectgo.WithServerURL("https://global.api.konghq.com"),
		sdkkonnectgo.WithSecurity(components.Security{
			PersonalAccessToken: sdkkonnectgo.String("<YOUR_BEARER_TOKEN_HERE>"),
		}),
	)

	res, err := s.ControlPlanes.ListControlPlanes(ctx, operations.ListControlPlanesRequest{
		PageSize:   sdkkonnectgo.Int64(10),
		PageNumber: sdkkonnectgo.Int64(1),
		Filter: &components.ControlPlaneFilterParameters{
			CloudGateway: sdkkonnectgo.Bool(true),
		},
		Labels: sdkkonnectgo.String("key:value,existCheck"),
		Sort:   sdkkonnectgo.String("name,created_at desc"),
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.ListControlPlanesResponse != nil {
		// handle response
	}
}

Override Server URL Per-Operation

The server URL can also be overridden on a per-operation basis, provided a server list was specified for the operation. For example:

package main

import (
	"context"
	sdkkonnectgo "github.com/Kong/sdk-konnect-go"
	"github.com/Kong/sdk-konnect-go/models/components"
	"github.com/Kong/sdk-konnect-go/models/operations"
	"log"
)

func main() {
	ctx := context.Background()

	s := sdkkonnectgo.New(
		sdkkonnectgo.WithSecurity(components.Security{
			PersonalAccessToken: sdkkonnectgo.String("<YOUR_BEARER_TOKEN_HERE>"),
		}),
	)

	res, err := s.Authentication.AuthenticateSso(ctx, "<value>", nil, operations.WithServerURL("https://global.api.konghq.com/"))
	if err != nil {
		log.Fatal(err)
	}
	if res != nil {
		// handle response
	}
}

Custom HTTP Client

The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

The built-in net/http client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.

import (
	"net/http"
	"time"
	"github.com/myorg/your-go-sdk"
)

var (
	httpClient = &http.Client{Timeout: 30 * time.Second}
	sdkClient  = sdk.New(sdk.WithClient(httpClient))
)

This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.

Authentication

Per-Client Security Schemes

This SDK supports the following security schemes globally:

NameTypeScheme
PersonalAccessTokenhttpHTTP Bearer
SystemAccountAccessTokenhttpHTTP Bearer
KonnectAccessTokenhttpHTTP Bearer

You can set the security parameters through the WithSecurity option when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:

package main

import (
	"context"
	sdkkonnectgo "github.com/Kong/sdk-konnect-go"
	"github.com/Kong/sdk-konnect-go/models/components"
	"github.com/Kong/sdk-konnect-go/models/operations"
	"log"
)

func main() {
	ctx := context.Background()

	s := sdkkonnectgo.New(
		sdkkonnectgo.WithSecurity(components.Security{
			PersonalAccessToken: sdkkonnectgo.String("<YOUR_BEARER_TOKEN_HERE>"),
		}),
	)

	res, err := s.ControlPlanes.ListControlPlanes(ctx, operations.ListControlPlanesRequest{
		PageSize:   sdkkonnectgo.Int64(10),
		PageNumber: sdkkonnectgo.Int64(1),
		Filter: &components.ControlPlaneFilterParameters{
			CloudGateway: sdkkonnectgo.Bool(true),
		},
		Labels: sdkkonnectgo.String("key:value,existCheck"),
		Sort:   sdkkonnectgo.String("name,created_at desc"),
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.ListControlPlanesResponse != nil {
		// handle response
	}
}

Summary

Konnect API - Go SDK: The Konnect platform API

For more information about the API: Documentation for Kong Gateway and its APIs

Table of Contents

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a retry.Config object to the call by using the WithRetries option:

package main

import (
	"context"
	sdkkonnectgo "github.com/Kong/sdk-konnect-go"
	"github.com/Kong/sdk-konnect-go/models/components"
	"github.com/Kong/sdk-konnect-go/models/operations"
	"github.com/Kong/sdk-konnect-go/retry"
	"log"
	"models/operations"
)

func main() {
	ctx := context.Background()

	s := sdkkonnectgo.New(
		sdkkonnectgo.WithSecurity(components.Security{
			PersonalAccessToken: sdkkonnectgo.String("<YOUR_BEARER_TOKEN_HERE>"),
		}),
	)

	res, err := s.ControlPlanes.ListControlPlanes(ctx, operations.ListControlPlanesRequest{
		PageSize:   sdkkonnectgo.Int64(10),
		PageNumber: sdkkonnectgo.Int64(1),
		Filter: &components.ControlPlaneFilterParameters{
			CloudGateway: sdkkonnectgo.Bool(true),
		},
		Labels: sdkkonnectgo.String("key:value,existCheck"),
		Sort:   sdkkonnectgo.String("name,created_at desc"),
	}, operations.WithRetries(
		retry.Config{
			Strategy: "backoff",
			Backoff: &retry.BackoffStrategy{
				InitialInterval: 1,
				MaxInterval:     50,
				Exponent:        1.1,
				MaxElapsedTime:  100,
			},
			RetryConnectionErrors: false,
		}))
	if err != nil {
		log.Fatal(err)
	}
	if res.ListControlPlanesResponse != nil {
		// handle response
	}
}

If you'd like to override the default retry strategy for all operations that support retries, you can use the WithRetryConfig option at SDK initialization:

package main

import (
	"context"
	sdkkonnectgo "github.com/Kong/sdk-konnect-go"
	"github.com/Kong/sdk-konnect-go/models/components"
	"github.com/Kong/sdk-konnect-go/models/operations"
	"github.com/Kong/sdk-konnect-go/retry"
	"log"
)

func main() {
	ctx := context.Background()

	s := sdkkonnectgo.New(
		sdkkonnectgo.WithRetryConfig(
			retry.Config{
				Strategy: "backoff",
				Backoff: &retry.BackoffStrategy{
					InitialInterval: 1,
					MaxInterval:     50,
					Exponent:        1.1,
					MaxElapsedTime:  100,
				},
				RetryConnectionErrors: false,
			}),
		sdkkonnectgo.WithSecurity(components.Security{
			PersonalAccessToken: sdkkonnectgo.String("<YOUR_BEARER_TOKEN_HERE>"),
		}),
	)

	res, err := s.ControlPlanes.ListControlPlanes(ctx, operations.ListControlPlanesRequest{
		PageSize:   sdkkonnectgo.Int64(10),
		PageNumber: sdkkonnectgo.Int64(1),
		Filter: &components.ControlPlaneFilterParameters{
			CloudGateway: sdkkonnectgo.Bool(true),
		},
		Labels: sdkkonnectgo.String("key:value,existCheck"),
		Sort:   sdkkonnectgo.String("name,created_at desc"),
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.ListControlPlanesResponse != nil {
		// handle response
	}
}

d

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

Bool provides a helper function to return a pointer to a bool.
Float32 provides a helper function to return a pointer to a float32.
Float64 provides a helper function to return a pointer to a float64.
Int provides a helper function to return a pointer to an int.
Int64 provides a helper function to return a pointer to an int64.
New creates a new instance of the SDK with the provided options.
Pointer provides a helper function to return a pointer to a type.
String provides a helper function to return a pointer to a string.
WithClient allows the overriding of the default HTTP client used by the SDK.
No description provided by the author
WithSecurity configures the SDK to use the provided security details.
WithSecuritySource configures the SDK to invoke the Security Source function on each method call to determine authentication.
WithServerIndex allows the overriding of the default server by index.
WithServerURL allows the overriding of the default server URL.
WithTemplatedServerURL allows the overriding of the default server URL with a templated URL populated with the provided parameters.
WithTimeout Optional request timeout applied to each operation.

# Variables

ServerList contains the list of servers available to the SDK.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
CACertificates - A CA certificate object represents a trusted certificate authority.
Certificates - A certificate object represents a public certificate, and can be optionally paired with the corresponding private key.
ConsumerGroups - Consumer groups enable the organization and categorization of consumers (users or applications) within an API ecosystem.
Consumers - The consumer object represents a consumer - or a user - of a service.
No description provided by the author
No description provided by the author
CustomPluginSchemas - Custom Plugin Schemas.
DPCertificates - DP Certificates.
DPNodes - DP Nodes.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Keys - A key object holds a representation of asymmetric keys in various formats.
KeySets - A JSON Web key set.
No description provided by the author
No description provided by the author
Plugins - A plugin entity represents a plugin configuration that will be executed during the HTTP request/response lifecycle.
No description provided by the author
Routes - Route entities define rules to match client requests.
SDK - Konnect API - Go SDK: The Konnect platform API https://docs.konghq.com - Documentation for Kong Gateway and its APIs.
Services - Service entities are abstractions of your microservice interfaces or formal APIs.
SNIs - An SNI object represents a many-to-one mapping of hostnames to a certificate.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Upstreams - The upstream object represents a virtual hostname and can be used to load balance incoming requests over multiple services (targets).
No description provided by the author
Vaults - Vault objects are used to configure different vault connectors for [managing secrets](https://docs.konghq.com/gateway/latest/kong-enterprise/secrets-management/).

# Interfaces

HTTPClient provides an interface for suplying the SDK with a custom HTTP client.

# Type aliases

No description provided by the author