Creating Thing

Once Getting Merle, create a workspace and create your Thing

Create Workspace

Create a working directory inside of the merle directory; I'm using "thing" for the Thing name in this example (due to lack of imagination). (Note per Go language convensions, the resulting Thing binary will have the same name as the directory. So in this example, the compiled binary will be ~go/bin/thing).

$ cd merle

$ mkdir thing

$ cd thing

Create a Thing

Copy the code below into thing.go.

This is nearly the bare minimum Thing you can make, so it's a good template to start with. All this one does is print "Hello!" when you browse to your Thing with a web browser.

thing.go

// file: thing/thing.go


package main


import "github.com/merliot/merle"


type thing struct {

}


func (t *thing) Subscribers() merle.Subscribers {

return merle.Subscribers{

merle.CmdRun: merle.RunForever,

}

}


func (t *thing) Assets() *merle.ThingAssets {

return &merle.ThingAssets{

HtmlTemplateText: "Hello!\n",

}

}


func main() {

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

thing.Cfg.PortPublic = 80 // run as web server on port :80

thing.Run()

}

Continue to Building Thing