Go
The Go SDK for the Neon API, generated from the same spec as the other nine.
Get the source
gh repo clone OctriDev/neon-go-showcase-sdkThe repository's README lists the toolchain and build commands for Go. Open it on GitHub.
Quickstart
package main
import (
"context"
"fmt"
"os"
sdk "github.com/OctriDev/neon-go-showcase-sdk"
)
func main() {
ctx := context.Background()
config := sdk.ClientConfig{
// Optional: replaces the default server and any server an operation declares.
BaseURL: "https://console.neon.tech/api/v2",
Auth: &sdk.ClientAuthConfig{BearerAuth: os.Getenv("API_TOKEN")},
}
client := sdk.NewNeon(config)
result, err := client.Branch.GetMaskingRules(ctx, sdk.GetMaskingRulesParams{ProjectId: "a", BranchId: "a"})
if err != nil {
panic(err)
}
fmt.Printf("%d masking_rules\n", len(result.MaskingRules))
}Authentication
Keep credentials outside source control. The quickstart reads them from the environment and the client applies them to every request.
| Scheme | ClientAuthConfig field | Sent as |
|---|---|---|
| BearerAuth | BearerAuth | Authorization: Bearer … |
| CookieAuth | CookieAuth | zenith in cookie |
| TokenCookieAuth | TokenCookieAuth | keycloak_token in cookie |
Client behavior
- Base URL:
https://console.neon.tech/api/v2. - Transport: net/http.
- Timeout: 30,000 ms per attempt.
- Retries: up to 3 attempts for status codes
408,425,429,500,502,503,504, with 500-8,000 ms backoff. - Idempotency: enabled for
POST,PATCHusingIdempotency-Key. - Error telemetry: off. This build has no reporting endpoint and sends no error reports.
High-level operation methods return the typed response body directly. The low-level request layer returns an SdkResponse<T> envelope containing data, status, headers, request ID, latency, and attempt count.
Errors
All failure paths use a small, predictable hierarchy:
| Error | Meaning |
|---|---|
SdkValidationError | A request argument failed an OpenAPI constraint before network I/O. |
SdkHttpError | The server returned a non-2xx response. |
SdkApiError | A 2xx response whose error envelope, when the API declares one, reports a failed call. It carries the envelope's error code. |
SdkResponseDecodeError | A 2xx response body or stream event did not decode into its declared type. It keeps the raw body. |
SdkNetworkError | DNS, connection, TLS, or socket failure. |
SdkTimeoutError | The configured per-attempt timeout elapsed. |
HTTP errors expose StatusCode, the response body and headers, plus RequestID when the server supplies one. Preserve the request ID in support logs; it is the fastest way to correlate a failed SDK call with server-side traces.
Match common statuses with errors.Is(err, ErrNotFound) against the sentinels ErrBadRequest (400), ErrUnauthorized (401), ErrPermissionDenied (403), ErrNotFound (404), ErrConflict (409), ErrUnprocessableEntity (422), ErrRateLimit (429), ErrInternalServer (any 5xx).
When the API declares a model for an error response, the SDK decodes the body into it as httpErr.Data, an ErrorBody to narrow with a type switch (a model declared as a type alias, such as a list, stays in the raw body). It is empty when the status declares no model or the body does not fit one. The raw body stays on the error either way, and DecodeErrorBody[ErrorModel](httpErr) decodes it into any ErrorModel by hand.