Go SDK for Neon Postgres SaaS Platform
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
Authentication
Authentication with the Neon Platform is implemented using variadic functions and environment variables evaluation in the following order:
- Variadic function client's argument;
- Environment variable
NEON_API_KEY
.
Note that if the API key is provided as the variadic function argument, key from the environment variable NEON_API_KEY
will be ignored.
Variadic Function
package main
import (
"log"
neon "github.com/kislerdm/neon-sdk-go"
)
func main() {
client, err := neon.NewClient(neon.WithAPIKey("{{.NeonApiKey}}"))
if err != nil {
panic(err)
}
v, err := client.ListProjects()
if err != nil {
panic(err)
}
log.Printf("%d projects found", len(v.Projects))
}
Environment Variables Evaluation
Requirement: a valid Neon API key must be exported as the environment variable NEON_API_KEY
.
package main
import (
"log"
neon "github.com/kislerdm/neon-sdk-go"
)
func main() {
client, err := neon.NewClient()
if err != nil {
panic(err)
}
v, err := client.ListProjects()
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.WithHTTPClient(neon.NewMockHTTPClient()))
if err != nil {
panic(err)
}
v, err := client.ListProjects()
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.
API V2
The SDK supports V2 only because V1 has been deprecated.
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.