Configuration

Thing Configuration is done through the Thing.Cfg structure. A newly created Thing has a default config, but config settings can be modified after creation but before running. Here we set the model and name of Thing and enable Basic HTTP Authentication for user "merle".


func main() {

thing := merle.NewThing(&gps{})


thing.Cfg.Model = "gps"

thing.Cfg.Name = "gypsy"

thing.Cfg.User = "merle"


thing.Run()

}


See ThingConfig structure for full list of Thing configuration settings. The defaults for most settings are sufficient for most use cases.


Using Flags

For flexibility, using Go's flag package let's us expose Thing configuration settings to user via command line parameters.


func main() {

thing := merle.NewThing(&gps{})


thing.Cfg.Model = "gps"

thing.Cfg.Name = "gypsy"

thing.Cfg.User = "merle"


flag.BoolVar(&thing.Cfg.IsPrime, "prime", false, "Run as Thing Prime")

flag.Parse()


thing.Run()

}


Gives us


$ ~/go/bin/thing -help

Usage of /home/merle/go/bin/thing:

-prime

Run as Thing Prime

You can also expose Thinger config settings using flags:


func main() {

gps := &gps{}

thing := merle.NewThing(gps)


thing.Cfg.Model = "gps"

thing.Cfg.Name = "gypsy"

thing.Cfg.User = "merle"


flag.StringVar(&g.tty, "dev", "/dev/ttyUSB3", "Serial device")

flag.BoolVar(&thing.Cfg.IsPrime, "prime", false, "Run as Thing Prime")

flag.Parse()


thing.Run()

}