keybox

package module
v0.0.0-...-285a9d7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2018 License: MIT Imports: 2 Imported by: 7

README

keybox

This is an extremely simple Go library that is merely a read-only key-value store for strings. Not much more than a convenience wrapper around the JSON decoder.

Installation

go get -u github.com/gbl08ma/keybox

Usage

The keybox reads the keys and values from a JSON file like this:

{
    "secretName": "th15i5mySeCrE7",
    "otherSecret": "passw0rd"
}

Use the keybox like this:

// ...

import "github.com/gbl08ma/keybox

// ...

var (
	secrets *keybox.Keybox
)

func main() {
    var err error
    secrets, err = keybox.Open("pathTo/FileWithSecrets.json")

    // now you can retrieve secrets like this:
    mySecret, present := secrets.Get("secretName")
	if !present {
		log.Fatal("Missing secret!")
	}
    // use mySecret
    AccessSecretStuff(mySecret)

    // ...
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Keybox

type Keybox struct {
	// contains filtered or unexported fields
}

A Keybox is a read-only object that stores secrets like API keys.

func Open

func Open(filename string) (*Keybox, error)

Open reads a Keybox from the specified file name. The should contain JSON-encoded map of key names to secrets.

func (*Keybox) Get

func (box *Keybox) Get(key string) (string, bool)

Get retrieves a key from the Keybox, returning the key and whether it is present in the Keybox.

func (*Keybox) GetBox

func (box *Keybox) GetBox(key string) (*Keybox, bool)

GetBox retrieves a nested Keybox from the Keybox, returning the Keybox and whether it is present in the Keybox.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL