From 1f23afcfcaba5d619a1a29558134ef6fba6960c5 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Sun, 25 Jan 2015 20:07:51 +0700 Subject: [PATCH] Readme draft --- README.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ manager.go | 3 +++ 2 files changed, 67 insertions(+) diff --git a/README.md b/README.md index 236ab23..7337cbd 100644 --- a/README.md +++ b/README.md @@ -1 +1,65 @@ # Confection + +Confection is a configuration manager plugin for Go projects. + +## Configuration + +First you need to add tags to fields of the config struct. + +* `json` — required for proper serialization +* `title` — human readable field name (optional) +* `attrs` — field attributes: `required`, `readonly`, `ignored`; separated by comma +* `options` — list of supported values, separated by comma + +Required attributes will block `manager.RequireConfig()` call until field gets a value + +Ignored attributes are not displayed. + +Readonly attributes are displayed but disabled. + +You also need to pass an unmarshalling function as shown below. + +```go +package main + +import ( + "encoding/json" + "flag" + "fmt" + + "github.com/localhots/confection" +) + +type ( + Config struct { + AppName string `json:"app_name" attrs:"required" title:"Application Name"` + BuildNumber int `json:"build_number" attrs:"readonly" title:"Build Number"` + } +) + +func init() { + confection.SetupFlags() + flag.Parse() +} + +func main() { + conf := Config{} + manager := confection.New(conf, func(b []byte) interface{} { + var newConf Config + if err := json.Unmarshal(b, &newConf); err != nil { + panic(err) + } + return newConf + }) + manager.StartServer() + manager.RequireConfig() + + fmt.Println("Ready to work!") +} +``` + +[Full example](https://github.com/localhots/confection/blob/master/demo/demo.go) + +## Demo Screenshot + + \ No newline at end of file diff --git a/manager.go b/manager.go index 7f22570..4aa0255 100644 --- a/manager.go +++ b/manager.go @@ -52,6 +52,9 @@ func (m *Manager) StartServer() { srv.start() } +func (m *Manager) RequireConfig() { +} + func (m *Manager) bootstrap() { if m.file.isExist() { b, err := m.file.read()