blah

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 13 Imported by: 0

README

github.com/speakeasy-sdks/blah

SDK Installation

go get github.com/speakeasy-sdks/blah

SDK Example Usage

Example
package main

import (
	"context"
	"github.com/speakeasy-sdks/blah"
	"log"
)

func main() {
	s := blah.New()

	ctx := context.Background()
	res, err := s.Echo.Jsonecho(ctx, []byte("0x4CcAf4eebe"))
	if err != nil {
		log.Fatal(err)
	}

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

Available Resources and Operations

Echo
BodyParams
ErrorCodes
FormParams
Header
QueryParam
ResponseTypes

Special Types

This SDK defines the following custom types to assist with marshalling and unmarshalling data.

Date

types.Date is a wrapper around time.Time that allows for JSON marshaling a date string formatted as "2006-01-02".

Usage
d1 := types.NewDate(time.Now()) // returns *types.Date

d2 := types.DateFromTime(time.Now()) // returns types.Date

d3, err := types.NewDateFromString("2019-01-01") // returns *types.Date, error

d4, err := types.DateFromString("2019-01-01") // returns types.Date, error

d5 := types.MustNewDateFromString("2019-01-01") // returns *types.Date and panics on error

d6 := types.MustDateFromString("2019-01-01") // returns types.Date and panics on error

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.NestedModelException 412 application/json
sdkerrors.GlobalTestException 500 application/json
sdkerrors.SDKError 4xx-5xx /
Example
package main

import (
	"context"
	"errors"
	"github.com/speakeasy-sdks/blah"
	"github.com/speakeasy-sdks/blah/pkg/models/sdkerrors"
	"log"
)

func main() {
	s := blah.New()

	ctx := context.Background()
	res, err := s.Echo.Jsonecho(ctx, []byte("0x4CcAf4eebe"))
	if err != nil {

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

		var e *sdkerrors.GlobalTestException
		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 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 Variables
0 http://localhost:3000 None
Example
package main

import (
	"context"
	"github.com/speakeasy-sdks/blah"
	"log"
)

func main() {
	s := blah.New(
		blah.WithServerIndex(0),
	)

	ctx := context.Background()
	res, err := s.Echo.Jsonecho(ctx, []byte("0x4CcAf4eebe"))
	if err != nil {
		log.Fatal(err)
	}

	if res.Res != nil {
		// 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"
	"github.com/speakeasy-sdks/blah"
	"log"
)

func main() {
	s := blah.New(
		blah.WithServerURL("http://localhost:3000"),
	)

	ctx := context.Background()
	res, err := s.Echo.Jsonecho(ctx, []byte("0x4CcAf4eebe"))
	if err != nil {
		log.Fatal(err)
	}

	if res.Res != 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"
	"github.com/speakeasy-sdks/blah"
	"log"
)

func main() {
	s := blah.New()

	ctx := context.Background()
	res, err := s.ResponseTypes.GetLong(ctx, operations.WithServerURL("http://localhost:3000"))
	if err != nil {
		log.Fatal(err)
	}

	if res.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.

Development

Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!

SDK Created by Speakeasy

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ServerList = []string{
	"http://localhost:3000",
}

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 BodyParams added in v0.3.0

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

func (*BodyParams) PostSendDate added in v0.3.0

func (s *BodyParams) PostSendDate(ctx context.Context, request []byte) (*operations.PostSendDateResponse, error)

PostSendDate - Send Date

func (*BodyParams) PostSendIntegerArray added in v0.3.0

PostSendIntegerArray - Send Integer Array

func (*BodyParams) PostSendIntegerEnumArray added in v0.3.0

PostSendIntegerEnumArray - SendIntegerEnumArray

func (*BodyParams) PostSendModel added in v0.3.0

func (s *BodyParams) PostSendModel(ctx context.Context, request shared.Employee) (*operations.PostSendModelResponse, error)

PostSendModel - Send Model

func (*BodyParams) PostSendRfc1123DateTime added in v0.3.0

func (s *BodyParams) PostSendRfc1123DateTime(ctx context.Context, request string) (*operations.PostSendRfc1123DateTimeResponse, error)

PostSendRfc1123DateTime - Send Rfc1123 DateTime

func (*BodyParams) PostSendRfc3339DateTime added in v0.3.0

func (s *BodyParams) PostSendRfc3339DateTime(ctx context.Context, request []byte) (*operations.PostSendRfc3339DateTimeResponse, error)

PostSendRfc3339DateTime - Send Rfc3339 DateTime

func (*BodyParams) PostSendStringArray added in v0.3.0

PostSendStringArray - Send String Array sends a string body param

func (*BodyParams) PostSendStringEnumArray added in v0.3.0

PostSendStringEnumArray - SendStringEnumArray

func (*BodyParams) PostSendUnixDateTime added in v0.3.0

func (s *BodyParams) PostSendUnixDateTime(ctx context.Context, request []byte) (*operations.PostSendUnixDateTimeResponse, error)

PostSendUnixDateTime - Send UnixDateTime

func (*BodyParams) SendDeleteBody added in v0.3.0

func (s *BodyParams) SendDeleteBody(ctx context.Context) (*operations.SendDeleteBodyResponse, error)

SendDeleteBody - send Delete Body

func (*BodyParams) SendDeleteBodywithModel added in v0.3.0

func (s *BodyParams) SendDeleteBodywithModel(ctx context.Context) (*operations.SendDeleteBodywithModelResponse, error)

SendDeleteBodywithModel - Send Delete Body with Model

func (*BodyParams) SendDeletePlainText added in v0.3.0

func (s *BodyParams) SendDeletePlainText(ctx context.Context) (*operations.SendDeletePlainTextResponse, error)

SendDeletePlainText - Send Delete PlainText

func (*BodyParams) SendDynamic added in v0.3.0

func (s *BodyParams) SendDynamic(ctx context.Context, request []byte) (*operations.SendDynamicResponse, error)

SendDynamic - Send Dynamic

func (*BodyParams) UpdateModel added in v0.3.0

func (s *BodyParams) UpdateModel(ctx context.Context, request shared.Employee) (*operations.UpdateModelResponse, error)

UpdateModel - Update Model

func (*BodyParams) UpdateString added in v0.3.0

func (s *BodyParams) UpdateString(ctx context.Context, request string) (*operations.UpdateStringResponse, error)

UpdateString - update String

type Echo added in v0.3.0

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

func (*Echo) Jsonecho added in v0.3.0

func (s *Echo) Jsonecho(ctx context.Context, request []byte, opts ...operations.Option) (*operations.JsonechoResponse, error)

Jsonecho - Json echo Echo's back the request

func (*Echo) QueryEcho added in v0.3.0

func (s *Echo) QueryEcho(ctx context.Context) (*operations.QueryEchoResponse, error)

QueryEcho

type ErrorCodes added in v0.3.0

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

func (*ErrorCodes) Catch412globalerror added in v0.3.0

func (s *ErrorCodes) Catch412globalerror(ctx context.Context, opts ...operations.Option) (*operations.Catch412globalerrorResponse, error)

Catch412globalerror - catch 412 global error

func (*ErrorCodes) Get400 added in v0.3.0

Get400

func (*ErrorCodes) Get401 added in v0.3.0

Get401

func (*ErrorCodes) Get500 added in v0.3.0

Get500

func (*ErrorCodes) Get501 added in v0.3.0

Get501

type FormParams added in v0.3.0

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

func (*FormParams) SendDate added in v0.3.0

SendDate - Send Date

func (*FormParams) SendDeleteMultipart added in v0.3.0

func (s *FormParams) SendDeleteMultipart(ctx context.Context) (*operations.SendDeleteMultipartResponse, error)

SendDeleteMultipart - send Delete Multipart

func (*FormParams) SendFile added in v0.3.0

SendFile - Send File

func (*FormParams) SendIntegerEnumArray added in v0.3.0

SendIntegerEnumArray

func (*FormParams) SendLong added in v0.3.0

SendLong - Send Long

func (*FormParams) SendMixedArray added in v0.3.0

SendMixedArray Send a variety for form params. Returns file count and body params

func (*FormParams) SendModel added in v0.3.0

SendModel - Send Model

func (*FormParams) SendRfc1123DateTime added in v0.3.0

SendRfc1123DateTime - Send Rfc1123 DateTime

func (*FormParams) SendRfc3339DateTime added in v0.3.0

SendRfc3339DateTime - Send Rfc3339 DateTime

func (*FormParams) SendStringArray added in v0.3.0

SendStringArray - Send String Array

func (*FormParams) SendStringEnumArray added in v0.3.0

SendStringEnumArray

func (*FormParams) SendUnixDateTime added in v0.3.0

SendUnixDateTime - Send UnixDateTime

func (*FormParams) SenddeleteForm added in v0.3.0

func (s *FormParams) SenddeleteForm(ctx context.Context) (*operations.SenddeleteFormResponse, error)

SenddeleteForm - send delete Form

func (*FormParams) SenddeleteForm1 added in v0.3.0

func (s *FormParams) SenddeleteForm1(ctx context.Context) (*operations.SenddeleteForm1Response, error)

SenddeleteForm1 - send delete Form1

func (*FormParams) UpdateModelwithForm added in v0.3.0

UpdateModelwithForm - Update Model with Form

func (*FormParams) UpdateStringwithForm added in v0.3.0

UpdateStringwithForm - update String with Form

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 Header struct {
	// contains filtered or unexported fields
}

func (*Header) SendHeaders added in v0.3.0

SendHeaders - Send Headers Sends a single header params

type QueryParam added in v0.3.0

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

func (*QueryParam) Date added in v0.3.0

Date

func (*QueryParam) DateArray added in v0.3.0

DateArray - Date Array

func (*QueryParam) IntegerEnumArray added in v0.3.0

IntegerEnumArray - Integer Enum Array

func (*QueryParam) MultipleParams added in v0.3.0

MultipleParams

func (*QueryParam) NoParams added in v0.3.0

NoParams

func (*QueryParam) NumberArray added in v0.3.0

NumberArray - Number Array

func (*QueryParam) OptionalDynamicQueryParam added in v0.3.0

OptionalDynamicQueryParam - Optional Dynamic Query Param get optional dynamic query parameter

func (*QueryParam) Rfc1123DateTime added in v0.3.0

Rfc1123DateTime - Rfc1123 DateTime

func (*QueryParam) Rfc1123DateTimeArray added in v0.3.0

Rfc1123DateTimeArray - Rfc1123 DateTime Array

func (*QueryParam) Rfc3339DateTime added in v0.3.0

Rfc3339DateTime - Rfc3339 DateTime

func (*QueryParam) Rfc3339DateTimeArray added in v0.3.0

Rfc3339DateTimeArray - Rfc3339 DateTime Array

func (*QueryParam) SimpleQuery added in v0.3.0

SimpleQuery

func (*QueryParam) StringArray added in v0.3.0

StringArray - String Array

func (*QueryParam) StringEnumArray added in v0.3.0

StringEnumArray - String Enum Array

func (*QueryParam) StringParam added in v0.3.0

StringParam

func (*QueryParam) URLParam added in v0.3.0

URLParam - UrlParam

func (*QueryParam) UnixDateTime added in v0.3.0

UnixDateTime - Unix DateTime

func (*QueryParam) UnixDateTimeArray added in v0.3.0

UnixDateTimeArray - Unix DateTime Array

type ResponseTypes added in v0.3.0

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

func (*ResponseTypes) Get1123DateTime added in v0.3.0

Get1123DateTime - Get 1123DateTime

func (*ResponseTypes) Get3339Datetime added in v0.3.0

Get3339Datetime - Get 3339Datetime

func (*ResponseTypes) GetBinary added in v0.3.0

GetBinary - Get Binary gets a binary object

func (*ResponseTypes) GetBoolean added in v0.3.0

GetBoolean - Get Boolean

func (*ResponseTypes) GetDateArray added in v0.3.0

GetDateArray - Get Date Array

func (*ResponseTypes) GetDynamic added in v0.3.0

GetDynamic - Get Dynamic

func (*ResponseTypes) GetHeaders added in v0.3.0

GetHeaders - Get Headers

func (*ResponseTypes) GetInteger added in v0.3.0

GetInteger - Get Integer Gets a integer response

func (*ResponseTypes) GetLong added in v0.3.0

GetLong - Get Long

func (*ResponseTypes) GetModelArray added in v0.3.0

GetModelArray - Get Model Array

func (*ResponseTypes) GetPrecision added in v0.3.0

GetPrecision - Get Precision

func (*ResponseTypes) GetStringEnumArray added in v0.3.0

GetStringEnumArray - Get String Enum Array

func (*ResponseTypes) GetUnixDateTime added in v0.3.0

GetUnixDateTime - Get UnixDateTime

func (*ResponseTypes) Getcontenttypeheaders added in v0.3.0

func (s *ResponseTypes) Getcontenttypeheaders(ctx context.Context) (*operations.GetcontenttypeheadersResponse, error)

Getcontenttypeheaders - get content type headers

func (*ResponseTypes) Returnresponsewithenums added in v0.3.0

func (s *ResponseTypes) Returnresponsewithenums(ctx context.Context) (*operations.ReturnresponsewithenumsResponse, error)

Returnresponsewithenums - return response with enums

type SDKOption

type SDKOption func(*Tester)

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 WithServerIndex

func WithServerIndex(serverIndex int) SDKOption

WithServerIndex allows the overriding of the default server by index

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 Tester

type Tester struct {
	Echo          *Echo
	BodyParams    *BodyParams
	ErrorCodes    *ErrorCodes
	FormParams    *FormParams
	Header        *Header
	QueryParam    *QueryParam
	ResponseTypes *ResponseTypes
	// contains filtered or unexported fields
}

Tester - Tester: Testing various

api

features

func New

func New(opts ...SDKOption) *Tester

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

Directories

Path Synopsis
internal
pkg

Jump to

Keyboard shortcuts

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