seconfig

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2018 License: MIT Imports: 5 Imported by: 0

README

seconfig

Lock your program's config file

usage
Step One

Create and initialize a config struct with data. You make your own Config type with its own fields.

Sorry, no func or chan fields!

type Config struct {
  Interface string,
  Port int,
  Name string,
}
config := Config{
  Interface: "0.0.0.0",
  Port:      8080,
  Name:      "my server",
}

Step Two

Marshal and encrypt the config struct into a slice of encrypted bytes. You will need the key provided here to access the data again.

b, err := Key([]byte("your-pass-phrase")).Marshal(config)
Step Three

Decrypt and unmarshal the data into a config struct. The pass phrase must be correct.

myconfig := new(Config)
err = Key([]byte("your-pass-phrase")).Unlock(b, &myconfig)


Documentation

Index

Constants

This section is empty.

Variables

View Source
var Pad = oldpad

Pad can be modified and probably should be for each version of your application.

Functions

This section is empty.

Types

type Key

type Key []byte

Key holds the password. You can use it like this:

seconf.Key([]byte("mypassword").Marshal(myConfigStruct)
seconf.Key([]byte("mypassword").Unmarshal(myEncryptedConfig)

It is up to the application to validate the key. Key size is 32 bits. If a key is too small, it will be padded using seconfig.Pad, which should be customized per application. If a key is too large, it will be truncated.

func (Key) Lock

func (c Key) Lock(v interface{}) (b []byte, err error)

Lock acts like JSON Marshal, which contents can only be seen after using seconf.Unlock https://godoc.org/encoding/json#Marshal

func (Key) Raw

func (c Key) Raw(data []byte) []byte

Raw data as []byte

func (Key) Unlock

func (c Key) Unlock(data []byte, v interface{}) (err error)

Unlock acts like JSON Unmarshal, but decrypting the data before unmarshaling. https://godoc.org/encoding/json#Unmarshal

Directories

Path Synopsis
example
seconfig-tester
Usage demo for seconfig package (https://github.com/aerth/seconfig)
Usage demo for seconfig package (https://github.com/aerth/seconfig)

Jump to

Keyboard shortcuts

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