Skip to content

nebhale/client-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

client-go

Tests GoDoc Go Report Card codecov

client-go is a library to access Service Binding Specification for Kubernetes conformant Service Binding Workload Projections.

Example

import (
	"context"
	"fmt"
	"github.com/jackc/pgx/v4"
	"github.com/nebhale/client-go/bindings"
	"os"
)

func main() {
	b := bindings.FromServiceBindingRoot()
	b = bindings.Filter(b, "postgresql")
	if len(b) != 1 {
		_, _ = fmt.Fprintf(os.Stderr, "Incorrect number of PostgreSQL drivers: %d\n", len(b))
		os.Exit(1)
	}

	u, ok := bindings.Get(b[0], "url")
	if !ok {
		_, _ = fmt.Fprintln(os.Stderr, "No URL in binding")
		os.Exit(1)
	}

	conn, err := pgx.Connect(context.Background(), u)
	if err != nil {
		_, _ = fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
		os.Exit(1)
	}
	defer conn.Close(context.Background())

	// ...
}

License

Apache License v2.0: see LICENSE for details.

About

Service Bindings for Kubernetes Go Client

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages