Documentation ¶
Overview ¶
Package seconf allows your software to store non-plaintext configuration files.
Example ¶
package main import ( "fmt" "os" "github.com/aerth/seconf" ) func main() { // Here is the new implementation using JSON filename := "se.conf" header := "Seconf" // []string of fields, they are both the prompt and key for looking the fields back up. fields := map[string]string{ "name": "What is your name?", "favorite-color": "What is your favorite color?", "lol": "You lol tho?", "password": "What is your password? Will not echo", } if !seconf.Detect(filename) { seconf.LockJSON(filename, header, fields) // Ask user for values return } c, err := seconf.ReadJSON(filename) if err != nil { fmt.Println(err) os.Exit(1) } fmt.Printf("%s's favorite color is %q!\n", c.Fields["name"], c.Fields["favorite-color"]) }
Output:
Index ¶
- Variables
- func AskForConfirmation() bool
- func ConfirmChoice(prompt string, def bool) bool
- func Create(secustom string, servicename string, arg ...string)
- func Destroy(secustom string) error
- func Detect(secustom string) bool
- func Exists(secustom string) bool
- func Locate(secustom string) (location string)
- func Lock(secustom string, servicename string, arg ...string) error
- func LockJSON(secustom string, servicename string, field map[string]string, ...) error
- func LockUnsafe(path string, configbytes []byte, key []byte) (n int, err error)
- func Pad(s string)
- func Prompt(prompt string) string
- func Read(secustom string) (config string, err error)
- func UnLockUnsafe(path string, key []byte) ([]byte, error)
- type Config
- type Seconf
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var NoBlank bool = false
NoBlank can be toggled to require a non-blank string for each field.
Functions ¶
func AskForConfirmation ¶
func AskForConfirmation() bool
AskForConfirmation returns true if the user types one of the "okayResponses" See also: ConfirmChoice() https://gist.github.com/albrow/5882501
func ConfirmChoice ¶
ConfirmChoice is like AskForConfirmation but with a default answer.
func Create ¶
Create initializes a new configuration file, at $HOME/secustom with the title servicename and as many fields as needed. Any field starting with "pass" will be assumed a password and input will not be echoed. Don't use Create(), use Lock() instead.
func Lock ¶
Lock() is the new version of Create(), It returns any errors during the process instead of using os.Exit()
func LockJSON ¶
func LockJSON(secustom string, servicename string, field map[string]string, fixedkey ...[1][]byte) error
LockJSON is the new version of Create(), It returns any errors during the process instead of using os.Exit()
func LockUnsafe ¶
LockUnsafe Allow an application to store config with default/no password.