Documentation
¶
Overview ¶
Package config allows Altid services to interact withe the ndb-formatted configuration files used by Altid
go get github.com/altid/libs/config
The ndb format is described in http://man.cat-v.org/plan_9/6/ndb
Usage ¶
This library has some special usage notes. Namely, on error it will return a string indicating the user should run `myservice -conf`. Doing so will call the Configurator which was passed in to config.New() and exit the program.
Repl ¶
The included Repl is meant to make designing Configurators much easier. To use, simply pass a struct to Repl with all the entries you wish described as type string|int|bool The struct tags will be used verbatim as the prompt message to the client
func myConfigurator(rw io.ReadCloser) (*config.Config, error) {
repl := struct {
Address string `IP Address of service`
Port int `Port to use`
UseTLS bool `Do you wish to use TLS?`
}{"localhost", 564, "false"}
return config.Repl(rw, repl, false)
}
This will start a repl with the client over the io.ReadWriter, using the struct tags as the prompt
$ IP Address of service [localhost]: (enter to use default) $ Port to use [564]: (enter to use default) $ Do you wish to use TLS? [no]: (enter to use default)
Index ¶
Examples ¶
Constants ¶
const ( ErrBadConfigurator = "configurator nil or invalid, cannot continue" ErrNoConfigure = "unable to find or create config for this service. To create one, please run %s -conf" ErrNoSuchKey = "no such key" ErrNoEntries = "unable to find config entry for this service." ErrMultiEntries = "config contains duplicate entries for this service" )
Errors
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶ added in v0.1.0
Config defines a services' configuration in a given config file
func Mock ¶
func Mock(c Configurator, service string, debug bool) (*Config, error)
Mock returns a mock config for a given service for testing It always calls Configurator to create a Config, and will not write to file
func New ¶ added in v0.1.0
func New(c Configurator, service string, debug bool) (*Config, error)
New returns a valid config for a given service. If one is not found, the Configurator will be called to interactively create one. On success, the program will exit
func Repl ¶
func Repl(rw io.ReadWriter, req interface{}, debug bool) (*Config, error)
Repl accepts a struct with String/Int/Bool types The fields should contain the default values, which will be presented to the client during the repl
Example ¶
package main
import (
"io"
"log"
"github.com/altid/libs/config"
)
func main() {
buildConfig := func(rw io.ReadWriter) (*config.Config, error) {
repl := struct {
Address string `IP address to dial`
Password string `password for service`
UseSSL bool `Use SSL?`
Foo string // Will use default
}{"127.0.0.1", "password", false, "bar"}
return config.Repl(rw, repl, false)
}
if _, e := config.Mock(buildConfig, "zzyzx", false); e != nil {
log.Fatal(e)
}
}
func (*Config) MustSearch ¶ added in v0.1.0
MustSearch returns a value or an empty string, if not found
func (*Config) Password ¶ added in v0.1.0
Password queries the database for a password the format in the config is auth=pass=mypassword or auth=factotum when auth=factotum is found, it will attempt to query the factotum for a response
func (*Config) SSLCert ¶ added in v0.1.0
func (c *Config) SSLCert() (tls.Certificate, error)
SSLCert returns a tls.Certificate based on successfully finding a cert and key file listen in the configuration
type Configurator ¶ added in v0.1.0
type Configurator func(io.ReadWriter) (*Config, error)
Configurator is called when no entry is found for a given service It should query the user for each required value, returning a complete and usable Config