GithubHelp home page GithubHelp logo

hartl3y94 / neon-sdk-go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kislerdm/neon-sdk-go

0.0 0.0 0.0 3.12 MB

Go SDK to communicate to Neon SaaS platform

License: MIT License

Go 99.62% Makefile 0.38%

neon-sdk-go's Introduction

Go SDK for Neon Postgres SaaS Platform

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

Authentication

Authentication with the Neon Platform is implemented using variadic functions and environment variables evaluation in the following order:

  1. Variadic function client's argument;
  2. 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.

neon-sdk-go's People

Contributors

kislerdm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.