Skip to content

scalar/galaxy-go-sdk

Repository files navigation

Scalar Galaxy

Generated Go SDK for Scalar Galaxy API. The Scalar Galaxy is an example OpenAPI document to test OpenAPI tools and libraries. It's a fictional universe with fictional planets and fictional data. Get all the data for all planets.

Resources

Markdown Support

All descriptions can contain tons of text Markdown. If GitHub supports the syntax, chances are we're supporting it, too. You can even create internal links to reference endpoints.

Examples

Blockquotes

I love OpenAPI. <3

Tables

Feature Availability
Markdown Support

Accordion

<details>
  <summary>Using Details Tags</summary>
  <p>HTML Example</p>
</details>

Images

Yes, there's support for images, too!

Empty placeholder image showing the width/height

Alerts

[!tip] You can now use markdown alerts in your descriptions.


Contents


Installation

go get github.com/scalar/galaxy-go-sdk

Usage

package main

import (
	"context"
	"fmt"
	"os"

	sdk "github.com/scalar/galaxy-go-sdk"
	"github.com/scalar/galaxy-go-sdk/option"
)

func main() {
	client := sdk.NewClient(
		option.WithBearerAuth(os.Getenv("BEARER_AUTH")),
	)

	planet, err := client.Planets.ListAllData(context.Background(), sdk.PlanetListAllDataParams{
		Limit: sdk.Int(10),
		Offset: sdk.Int(0),
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(planet)
}

The examples in the following sections assume a client configured as shown above.

See the API reference for every available operation.


Authentication

Pass credentials to the generated client constructor. Environment variables are read automatically when supported by the target runtime.

Option Type Default Description
option.WithBearerAuth string | provider - JWT Bearer token authentication Defaults to BEARER_AUTH.
option.WithBasicAuthUsername string | provider - Credential for the basicAuth_username client option. Defaults to BASIC_AUTH_USERNAME.
option.WithBasicAuthPassword string | provider - Credential for the basicAuth_password client option. Defaults to BASIC_AUTH_PASSWORD.
option.WithAPIKeyHeader string | provider - API key request header Defaults to API_KEY_HEADER.
option.WithAPIKeyQuery string | provider - API key query parameter Defaults to API_KEY_QUERY.
option.WithAPIKeyCookie string | provider - API key browser cookie Defaults to API_KEY_COOKIE.
option.WithOAuth2 string | provider - OAuth 2.0 authentication Defaults to SCALAR_OAUTH2.
option.WithOpenIDConnect string | provider - OpenID Connect Authentication Defaults to SCALAR_OPEN_IDCONNECT.

Declared schemes:

  • bearerAuth bearer token
  • basicAuth basic authentication
  • apiKeyHeader API key in header X-API-Key
  • apiKeyQuery API key in query api_key
  • apiKeyCookie API key in cookie api_key
  • oAuth2 OAuth2/OpenID Connect
  • openIdConnect OAuth2/OpenID Connect

Errors

Non-success responses return generated API errors. Error objects expose status, headers, response body, and request metadata where the target runtime supports it.

planet, err := client.Planets.ListAllData(context.Background(), sdk.PlanetListAllDataParams{
if err != nil {
	var apiErr *sdk.Error
	if errors.As(err, &apiErr) {
		fmt.Println(apiErr.StatusCode, apiErr.RawJSON())
	}
	panic(err)
}

// imports: sdk "github.com/scalar/galaxy-go-sdk", "errors", "fmt"

Documented error statuses: 400, 401, 403, 404, 409, 422.


Client Options

Configure the generated client by setting any of these options when you create it.

client := sdk.NewClient(
	option.WithBaseURL("https://api.example.com"),
	option.WithMaxRetries(2),
	option.WithTimeout(60*time.Second),
)

// imports: sdk "github.com/scalar/galaxy-go-sdk", "github.com/scalar/galaxy-go-sdk/option", "time"
Option Type Default Description
option.WithBearerAuth func(string) option.RequestOption os.Getenv("BEARER_AUTH") JWT Bearer token authentication
option.WithBasicAuthUsername func(string) option.RequestOption os.Getenv("BASIC_AUTH_USERNAME") Credential for the basicAuth_username client option.
option.WithBasicAuthPassword func(string) option.RequestOption os.Getenv("BASIC_AUTH_PASSWORD") Credential for the basicAuth_password client option.
option.WithAPIKeyHeader func(string) option.RequestOption os.Getenv("API_KEY_HEADER") API key request header
option.WithAPIKeyQuery func(string) option.RequestOption os.Getenv("API_KEY_QUERY") API key query parameter
option.WithAPIKeyCookie func(string) option.RequestOption os.Getenv("API_KEY_COOKIE") API key browser cookie
option.WithOAuth2 func(string) option.RequestOption os.Getenv("SCALAR_OAUTH2") OAuth 2.0 authentication
option.WithOpenIDConnect func(string) option.RequestOption os.Getenv("SCALAR_OPEN_IDCONNECT") OpenID Connect Authentication
option.WithEnvironmentProduction func() option.RequestOption - Select the production API environment.
option.WithEnvironmentRespondsWithYourRequestData func() option.RequestOption - Select the responds_with_your_request_data API environment.
option.WithBaseURL func(string) option.RequestOption os.Getenv("SCALAR_BASE_URL") Override the default API base URL.
option.WithTimeout func(time.Duration) option.RequestOption - Maximum time to wait for each request attempt.
option.WithMaxRetries func(int) option.RequestOption 2 Number of retries for temporary failures.
option.WithHTTPClient func(option.HTTPClient) option.RequestOption - Custom HTTP client or transport implementation.

Request Options

Option Type Default Description
option.WithHeader func(string, string) option.RequestOption - Set a per-request header.
option.WithQuery func(string, string) option.RequestOption - Set a per-request query parameter.
option.WithRequestBody func(string, any) option.RequestOption - Override the serialized request body and content type.
option.WithResponseInto func(**http.Response) option.RequestOption - Capture the raw HTTP response.
option.WithResponseBodyInto func(any) option.RequestOption - Override the response deserialization target.

Retries and Timeouts

Generated clients support request timeouts and retry temporary failures such as network errors, 408, 409, 429, and 5xx responses. Retry delays honor Retry-After headers when present. Tune the retry and timeout client options shown above, or override them per request.


Helpers

  • Pass option.WithResponseInto(&raw) to capture the underlying *http.Response for a request.
  • Use the generated String, Int, Bool, Float, Time, Opt, and Ptr helpers when setting optional params.

Logging

  • Wrap the HTTP client with option.WithMiddleware(...) to add request logging or tracing.

Requirements

  • Go 1.22 or newer

Powered by Scalar.

Contributions

This SDK is generated programmatically. Manual edits to generated files will be overwritten on the next build.

SDK created by Scalar

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages