speakeasyclientsdkgo

package module
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

README

github.com/speakeasy-api/speakeasy-client-sdk-go

SDK Installation

go get github.com/speakeasy-api/speakeasy-client-sdk-go

SDK Example Usage

Example
package main

import (
	"context"
	speakeasyclientsdkgo "github.com/speakeasy-api/speakeasy-client-sdk-go/v3"
	"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/operations"
	"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/shared"
	"log"
)

func main() {
	s := speakeasyclientsdkgo.New(
		speakeasyclientsdkgo.WithSecurity("<YOUR_API_KEY_HERE>"),
	)

	ctx := context.Background()
	res, err := s.Apis.GetApis(ctx, operations.GetApisRequest{
		Metadata: map[string][]string{
			"key": []string{
				"string",
			},
		},
		Op: &operations.QueryParamOp{
			And: false,
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	if res.Classes != nil {
		// handle response
	}
}

Available Resources and Operations

Speakeasy SDK
Apis
APIEndpoints
Metadata
Schemas
Requests
Plugins
Embeds

Special Types

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both. When specified by the OpenAPI spec document, the SDK will return the appropriate subclass.

Error Object Status Code Content Type
sdkerrors.SDKError 4xx-5xx /
Example
package main

import (
	"context"
	"errors"
	speakeasyclientsdkgo "github.com/speakeasy-api/speakeasy-client-sdk-go/v3"
	"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/sdkerrors"
	"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/shared"
	"log"
)

func main() {
	s := speakeasyclientsdkgo.New(
		speakeasyclientsdkgo.WithSecurity("<YOUR_API_KEY_HERE>"),
	)

	ctx := context.Background()
	res, err := s.ValidateAPIKey(ctx)
	if err != nil {

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

Server Selection

Select Server by Name

You can override the default server globally using the WithServer 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 names associated with the available servers:

Name Server Variables
prod https://api.prod.speakeasyapi.dev None
Example
package main

import (
	"context"
	speakeasyclientsdkgo "github.com/speakeasy-api/speakeasy-client-sdk-go/v3"
	"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/shared"
	"log"
	"net/http"
)

func main() {
	s := speakeasyclientsdkgo.New(
		speakeasyclientsdkgo.WithServer("prod"),
		speakeasyclientsdkgo.WithSecurity("<YOUR_API_KEY_HERE>"),
	)

	ctx := context.Background()
	res, err := s.ValidateAPIKey(ctx)
	if err != nil {
		log.Fatal(err)
	}

	if res.StatusCode == http.StatusOK {
		// handle response
	}
}

Override Server URL Per-Client

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

package main

import (
	"context"
	speakeasyclientsdkgo "github.com/speakeasy-api/speakeasy-client-sdk-go/v3"
	"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/shared"
	"log"
	"net/http"
)

func main() {
	s := speakeasyclientsdkgo.New(
		speakeasyclientsdkgo.WithServerURL("https://api.prod.speakeasyapi.dev"),
		speakeasyclientsdkgo.WithSecurity("<YOUR_API_KEY_HERE>"),
	)

	ctx := context.Background()
	res, err := s.ValidateAPIKey(ctx)
	if err != nil {
		log.Fatal(err)
	}

	if res.StatusCode == http.StatusOK {
		// 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 scheme globally:

Name Type Scheme
APIKey apiKey API key

You can configure it using the WithSecurity option when initializing the SDK client instance. For example:

package main

import (
	"context"
	speakeasyclientsdkgo "github.com/speakeasy-api/speakeasy-client-sdk-go/v3"
	"log"
	"net/http"
)

func main() {
	s := speakeasyclientsdkgo.New(
		speakeasyclientsdkgo.WithSecurity("<YOUR_API_KEY_HERE>"),
	)

	ctx := context.Background()
	res, err := s.ValidateAPIKey(ctx)
	if err != nil {
		log.Fatal(err)
	}

	if res.StatusCode == http.StatusOK {
		// handle response
	}
}

SDK Generated by Speakeasy

Documentation

Index

Constants

View Source
const (
	ServerProd string = "prod"
)

Variables

View Source
var ServerList = map[string]string{
	ServerProd: "https://api.prod.speakeasyapi.dev",
}

ServerList contains the list of servers available to the SDK

Functions

func Bool

func Bool(b bool) *bool

Bool provides a helper function to return a pointer to a bool

func Float32

func Float32(f float32) *float32

Float32 provides a helper function to return a pointer to a float32

func Float64

func Float64(f float64) *float64

Float64 provides a helper function to return a pointer to a float64

func Int

func Int(i int) *int

Int provides a helper function to return a pointer to an int

func Int64

func Int64(i int64) *int64

Int64 provides a helper function to return a pointer to an int64

func String

func String(s string) *string

String provides a helper function to return a pointer to a string

Types

type APIEndpoints

type APIEndpoints struct {
	// contains filtered or unexported fields
}

APIEndpoints - REST APIs for managing ApiEndpoint entities

func (*APIEndpoints) DeleteAPIEndpoint

DeleteAPIEndpoint - Delete an ApiEndpoint. Delete an ApiEndpoint. This will also delete all associated Request Logs (if using a Postgres datastore).

func (*APIEndpoints) FindAPIEndpoint

FindAPIEndpoint - Find an ApiEndpoint via its displayName. Find an ApiEndpoint via its displayName (set by operationId from a registered OpenAPI schema). This is useful for finding the ID of an ApiEndpoint to use in the /v1/apis/{apiID}/version/{versionID}/api_endpoints/{apiEndpointID} endpoints.

func (*APIEndpoints) GenerateOpenAPISpecForAPIEndpoint

GenerateOpenAPISpecForAPIEndpoint - Generate an OpenAPI specification for a particular ApiEndpoint. This endpoint will generate a new operation in any registered OpenAPI document if the operation does not already exist in the document. Returns the original document and the newly generated document allowing a diff to be performed to see what has changed.

func (*APIEndpoints) GeneratePostmanCollectionForAPIEndpoint

GeneratePostmanCollectionForAPIEndpoint - Generate a Postman collection for a particular ApiEndpoint. Generates a postman collection that allows the endpoint to be called from postman variables produced for any path/query/header parameters included in the OpenAPI document.

func (*APIEndpoints) GetAPIEndpoint

GetAPIEndpoint - Get an ApiEndpoint.

func (*APIEndpoints) GetAllAPIEndpoints

GetAllAPIEndpoints - Get all Api endpoints for a particular apiID.

func (*APIEndpoints) GetAllForVersionAPIEndpoints

GetAllForVersionAPIEndpoints - Get all ApiEndpoints for a particular apiID and versionID.

func (*APIEndpoints) UpsertAPIEndpoint

UpsertAPIEndpoint - Upsert an ApiEndpoint. Upsert an ApiEndpoint. If the ApiEndpoint does not exist it will be created, otherwise it will be updated.

type Apis

type Apis struct {
	// contains filtered or unexported fields
}

Apis - REST APIs for managing Api entities

func (*Apis) DeleteAPI

DeleteAPI - Delete an Api. Delete a particular version of an Api. The will also delete all associated ApiEndpoints, Metadata, Schemas & Request Logs (if using a Postgres datastore).

func (*Apis) GenerateOpenAPISpec

GenerateOpenAPISpec - Generate an OpenAPI specification for a particular Api. This endpoint will generate any missing operations in any registered OpenAPI document if the operation does not already exist in the document. Returns the original document and the newly generated document allowing a diff to be performed to see what has changed.

func (*Apis) GeneratePostmanCollection

GeneratePostmanCollection - Generate a Postman collection for a particular Api. Generates a postman collection containing all endpoints for a particular API. Includes variables produced for any path/query/header parameters included in the OpenAPI document.

func (*Apis) GetAllAPIVersions

GetAllAPIVersions - Get all Api versions for a particular ApiEndpoint. Get all Api versions for a particular ApiEndpoint. Supports filtering the versions based on metadata attributes.

func (*Apis) GetApis

GetApis - Get a list of Apis for a given workspace Get a list of all Apis and their versions for a given workspace. Supports filtering the APIs based on metadata attributes.

func (*Apis) UpsertAPI

UpsertAPI - Upsert an Api Upsert an Api. If the Api does not exist, it will be created. If the Api exists, it will be updated.

type Embeds

type Embeds struct {
	// contains filtered or unexported fields
}

Embeds - REST APIs for managing embeds

func (*Embeds) GetEmbedAccessToken

GetEmbedAccessToken - Get an embed access token for the current workspace. Returns an embed access token for the current workspace. This can be used to authenticate access to externally embedded content. Filters can be applied allowing views to be filtered to things like particular customerIds.

func (*Embeds) GetValidEmbedAccessTokens

func (s *Embeds) GetValidEmbedAccessTokens(ctx context.Context) (*operations.GetValidEmbedAccessTokensResponse, error)

GetValidEmbedAccessTokens - Get all valid embed access tokens for the current workspace.

func (*Embeds) RevokeEmbedAccessToken

RevokeEmbedAccessToken - Revoke an embed access EmbedToken.

type HTTPClient

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

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

type Metadata

type Metadata struct {
	// contains filtered or unexported fields
}

Metadata - REST APIs for managing Version Metadata entities

func (*Metadata) DeleteVersionMetadata

DeleteVersionMetadata - Delete metadata for a particular apiID and versionID.

func (*Metadata) GetVersionMetadata

GetVersionMetadata - Get all metadata for a particular apiID and versionID.

func (*Metadata) InsertVersionMetadata

InsertVersionMetadata - Insert metadata for a particular apiID and versionID.

type Plugins

type Plugins struct {
	// contains filtered or unexported fields
}

Plugins - REST APIs for managing and running plugins

func (*Plugins) GetPlugins

func (s *Plugins) GetPlugins(ctx context.Context) (*operations.GetPluginsResponse, error)

GetPlugins - Get all plugins for the current workspace.

func (*Plugins) RunPlugin

RunPlugin - Run a plugin

func (*Plugins) UpsertPlugin

func (s *Plugins) UpsertPlugin(ctx context.Context, request shared.Plugin) (*operations.UpsertPluginResponse, error)

UpsertPlugin - Upsert a plugin

type Requests

type Requests struct {
	// contains filtered or unexported fields
}

Requests - REST APIs for retrieving request information

func (*Requests) GenerateRequestPostmanCollection

GenerateRequestPostmanCollection - Generate a Postman collection for a particular request. Generates a Postman collection for a particular request. Allowing it to be replayed with the same inputs that were captured by the SDK.

func (*Requests) GetRequestFromEventLog

GetRequestFromEventLog - Get information about a particular request.

func (*Requests) QueryEventLog

QueryEventLog - Query the event log to retrieve a list of requests. Supports retrieving a list of request captured by the SDK for this workspace. Allows the filtering of requests on a number of criteria such as ApiID, VersionID, Path, Method, etc.

type SDKOption

type SDKOption func(*Speakeasy)

func WithClient

func WithClient(client HTTPClient) SDKOption

WithClient allows the overriding of the default HTTP client used by the SDK

func WithRetryConfig

func WithRetryConfig(retryConfig utils.RetryConfig) SDKOption

func WithSecurity

func WithSecurity(apiKey string) SDKOption

WithSecurity configures the SDK to use the provided security details

func WithSecuritySource

func WithSecuritySource(security func(context.Context) (shared.Security, error)) SDKOption

WithSecuritySource configures the SDK to invoke the Security Source function on each method call to determine authentication

func WithServer

func WithServer(server string) SDKOption

WithServer allows the overriding of the default server by name

func WithServerURL

func WithServerURL(serverURL string) SDKOption

WithServerURL allows the overriding of the default server URL

func WithTemplatedServerURL

func WithTemplatedServerURL(serverURL string, params map[string]string) SDKOption

WithTemplatedServerURL allows the overriding of the default server URL with a templated URL populated with the provided parameters

type Schemas

type Schemas struct {
	// contains filtered or unexported fields
}

Schemas - REST APIs for managing Schema entities

func (*Schemas) DeleteSchema

DeleteSchema - Delete a particular schema revision for an Api.

func (*Schemas) DownloadSchema

DownloadSchema - Download the latest schema for a particular apiID.

func (*Schemas) DownloadSchemaRevision

DownloadSchemaRevision - Download a particular schema revision for an Api.

func (*Schemas) GetSchema

GetSchema - Get information about the latest schema. Returns information about the last uploaded schema for a particular API version. This won't include the schema itself, that can be retrieved via the downloadSchema operation.

func (*Schemas) GetSchemaDiff

GetSchemaDiff - Get a diff of two schema revisions for an Api.

func (*Schemas) GetSchemaRevision

GetSchemaRevision - Get information about a particular schema revision for an Api. Returns information about the last uploaded schema for a particular schema revision. This won't include the schema itself, that can be retrieved via the downloadSchema operation.

func (*Schemas) GetSchemas

GetSchemas - Get information about all schemas associated with a particular apiID. Returns information the schemas associated with a particular apiID. This won't include the schemas themselves, they can be retrieved via the downloadSchema operation.

func (*Schemas) RegisterSchema

RegisterSchema - Register a schema. Allows uploading a schema for a particular API version. This will be used to populate ApiEndpoints and used as a base for any schema generation if present.

type Speakeasy

type Speakeasy struct {
	// REST APIs for managing Api entities
	Apis *Apis
	// REST APIs for managing ApiEndpoint entities
	APIEndpoints *APIEndpoints
	// REST APIs for managing Version Metadata entities
	Metadata *Metadata
	// REST APIs for managing Schema entities
	Schemas *Schemas
	// REST APIs for retrieving request information
	Requests *Requests
	// REST APIs for managing and running plugins
	Plugins *Plugins
	// REST APIs for managing embeds
	Embeds *Embeds
	// contains filtered or unexported fields
}

Speakeasy API: The Speakeasy API allows teams to manage common operations with their APIs

/docs - The Speakeasy Platform Documentation

func New

func New(opts ...SDKOption) *Speakeasy

New creates a new instance of the SDK with the provided options

func (*Speakeasy) ValidateAPIKey

func (s *Speakeasy) ValidateAPIKey(ctx context.Context) (*operations.ValidateAPIKeyResponse, error)

ValidateAPIKey - Validate the current api key.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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