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.
- https://github.com/scalar/scalar
- https://github.com/OAI/OpenAPI-Specification
- https://scalar.com
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!
Alerts
[!tip] You can now use markdown alerts in your descriptions.
- Installation
- Usage
- API Reference
- Authentication
- Errors
- Client Options
- Request Options
- Retries and Timeouts
- Helpers
- Logging
- Requirements
go get github.com/scalar/galaxy-go-sdkpackage 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.
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:
bearerAuthbearer tokenbasicAuthbasic authenticationapiKeyHeaderAPI key in headerX-API-KeyapiKeyQueryAPI key in queryapi_keyapiKeyCookieAPI key in cookieapi_keyoAuth2OAuth2/OpenID ConnectopenIdConnectOAuth2/OpenID Connect
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.
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. |
| 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. |
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.
- Pass
option.WithResponseInto(&raw)to capture the underlying*http.Responsefor a request. - Use the generated
String,Int,Bool,Float,Time,Opt, andPtrhelpers when setting optional params.
- Wrap the HTTP client with
option.WithMiddleware(...)to add request logging or tracing.
- Go 1.22 or newer
Powered by Scalar.
This SDK is generated programmatically. Manual edits to generated files will be overwritten on the next build.