Categorygithub.com/kislerdm/neon-sdk-go
modulepackage
0.6.2
Repository: https://github.com/kislerdm/neon-sdk-go.git
Documentation: pkg.go.dev

# README

Go SDK for Neon Postgres SaaS Platform


⭐ The project needs your support! Please leave a star and become a GitHub sponsor! ⭐

💖 Thank you @neondatabase for sponsoring the project! 💖

logo

Go Report Card codecov Licenses Check

The SDK to manage Neon Platform programmatically.

Neon is a fully managed serverless PostgreSQL with a generous free tier. Neon separates storage and compute and offers modern developer features such as serverless, branching, bottomless storage, and more. Neon is open source and written in Rust.

Find more about Neon here.

How to use

Prerequisites

Installation

Add the SDK as a module dependency:

go get github.com/kislerdm/neon-sdk-go

Run to specify the release version:

go get github.com/kislerdm/neon-sdk-go@{{.Ver}}

Where {{.Ver}} is the release version.

Code Snippets

Default HTTP Client

The following snippet demonstrates how to initialize SDK which will use default HTTP client.

package main

import (
	"log"

	neon "github.com/kislerdm/neon-sdk-go"
)

func main() {
	client, err := neon.NewClient(neon.Config{Key: "{{.NeonApiKey}}"})
	if err != nil {
		panic(err)
	}

	v, err := client.ListProjects(nil, nil, nil)
	if err != nil {
		panic(err)
	}

	log.Printf("%d projects found", len(v.Projects))
}

Custom HTTP client

The SDK can initialized with a custom HTTP client.

package main

import (
	"net/http"
	"log"
	"time"

	neon "github.com/kislerdm/neon-sdk-go"
)

func main() {
	myHTTPClient := &http.Client{Timeout: 30 * time.Second}

	client, err := neon.NewClient(neon.Config{Key: "{{.NeonApiKey}}", HTTPClient: myHTTPClient})
	if err != nil {
		panic(err)
	}

	v, err := client.ListProjects(nil, nil, nil)
	if err != nil {
		panic(err)
	}

	log.Printf("%d projects found", len(v.Projects))
}

Mock

The SDK provides the http client's mock for unit tests. An example snippet is shown below.

package main

import (
	"log"

	neon "github.com/kislerdm/neon-sdk-go"
)

func main() {
	client, err := neon.NewClient(neon.Config{HTTPClient: neon.NewMockHTTPClient()})
	if err != nil {
		panic(err)
	}

	v, err := client.ListProjects(nil, nil, nil)
	if err != nil {
		panic(err)
	}

	log.Printf("%d projects found", len(v.Projects))
}

Development

The SDK codebase is generated using the OpenAPI from the API reference page. The generator application codebase can be found here.

Commands

Prerequisites:

  • go ~> 1.18
  • gnuMake / cmake

Run to see all available commands:

make help

Run to generate the SDK codebase and store it to PWD, given the OpenAPI spec is available in the file openAPIDefinition.json:

make generate-sdk

Set the flag SKIP_TEST=1 to generate the codebase without running the unit tests afterward:

SKIP_TEST=1 make generate-sdk

Run to customise the locations:

make generate-sdk PATH_SDK=##/PATH/TO/OUTPUT/SDK/CODE## PATH_SPEC=##/PATH/TO/SPEC.json##

Run to test generated SDK:

make tests

Run to test generated SDK stored to /PATH/TO/OUTPUT/SDK/CODE:

make tests DIR=/PATH/TO/OUTPUT/SDK/CODE

Run to test the code generator:

make tests DIR=generator

Run to build the code generator:

make build DIR=generator

Contribution

The SDK is distributed under the MIT license, find full list of dependencies' licenses here.

Please feel free to open an issue ticket, or PR to contribute.

# Functions

NewClient initialised the Client to communicate to the Neon Platform.
NewMockHTTPClient initiates a mock fo the HTTP client required for the SDK client.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

AllowedIps A list of IP addresses that are allowed to connect to the compute endpoint.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
BranchCreatedBy The resolved user model that contains details of the user/org/integration/api_key used for branch creation.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Client defines the Neon SDK client.
Config defines the client's configuration.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
DefaultEndpointSettings A collection of settings for a Neon endpoint.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
EndpointSettingsData A collection of settings for a compute endpoint.
No description provided by the author
No description provided by the author
No description provided by the author
Error API error.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Pagination Cursor based pagination is used.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ProjectListItem Essential data about the project.
No description provided by the author
No description provided by the author
No description provided by the author
ProjectQuota Per-project consumption quota.
No description provided by the author
ProjectsApplicationsMapResponse A map where key is a project ID and a value is a list of available applications.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

HTTPClient client to handle http requests.

# Type aliases

No description provided by the author
AnnotationValueData Annotation properties.
BillingPaymentMethod Indicates whether and how an account makes payments.
BillingSubscriptionType Type of subscription to Neon Cloud.
BranchState The branch state.
No description provided by the author
No description provided by the author
EmptyResponse Empty response.
EndpointPoolerMode The connection pooler mode.
EndpointState The state of the compute endpoint.
EndpointType The compute endpoint type.
IdentityProviderId Identity provider id from keycloak.
OperationAction The action performed by the operation.
OperationStatus The status of the operation.
PgbouncerSettingsData A raw representation of PgBouncer settings.
PgSettingsData A raw representation of Postgres settings.
PgVersion The major Postgres version number.
No description provided by the author
Provisioner The Neon compute provisioner.
SuspendTimeoutSeconds Duration of inactivity in seconds after which the compute endpoint is automatically suspended.