1
0
Fork 0
Configuration tool with a GUI
Go to file
Gregory Eremin 1f23afcfca Readme draft 2015-01-25 20:07:51 +07:00
demo Add screenshot 2015-01-25 19:48:28 +07:00
static Saving 2015-01-25 19:34:24 +07:00
.gitignore Initial commit 2015-01-18 17:50:03 +07:00
README.md Readme draft 2015-01-25 20:07:51 +07:00
config.go Include ignored fields 2015-01-25 19:33:01 +07:00
config_file.go Fix config file opening 2015-01-25 19:34:34 +07:00
manager.go Readme draft 2015-01-25 20:07:51 +07:00
server.go Response to saving with something 2015-01-25 19:33:46 +07:00

README.md

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.

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

Demo Screenshot