Example #1
0
func main() {

	app := cli.NewApp()
	api = fantail.InitApi()

	app.Name = "D-mate"
	app.Usage = "Allow you to interact with your diabates data locally"
	app.Version = "0.0.1"
	app.Author = "Jamie Bate"
	app.Email = "*****@*****.**"

	app.Commands = []cli.Command{

		//e.g. import --type smbg --data "[{"value": 5.5, "time": "2015-05-16T10:42:57.539Z" }]"
		{
			Name:      "import",
			ShortName: "i",
			Usage:     "import diabetes data",
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "d, data",
					Usage: "the data value(s) that you want to save e.g. [`{\"value\": 5.5, \"time\": \"2015-05-16T10:42:57.539Z\" }`, `{\"value\": 7.5, \"time\": \"2015-05-16T11:42:57.539Z\" }`, ...]",
				},
				cli.StringFlag{
					Name:  "t, type",
					Usage: "the type of event(s) you are adding e.g. smbg",
				},
			},
			Action: importData,
		},
		//e.g. export --type smbg
		{
			Name:      "export",
			ShortName: "e",
			Usage:     "export diabetes data",
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "t, type",
					Usage: "the type of event(s) you are adding e.g. smbg",
				},
				cli.StringFlag{
					Name:  "f, file",
					Value: "_eventdata.json",
					Usage: "the name of the file you want to sve it too",
				},
			},
			Action: exportData,
		},
	}

	app.Run(os.Args)

}
Example #2
0
	"strings"
	"text/template"

	"github.com/gorilla/mux"

	"github.com/jh-bate/fantail"
	"github.com/jh-bate/fantail/users"
)

type Fantail struct {
	logger *log.Logger
	api    *fantail.Api
}

var f = &Fantail{
	api:    fantail.InitApi(),
	logger: log.New(os.Stdout, "faintail/chat", log.Lshortfile),
}

var addr = flag.String("addr", ":8080", "http service address")
var homeTempl = template.Must(template.ParseFiles("./static/index.html"))

var homeHandler = http.HandlerFunc(serveHome)

func serveHome(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	homeTempl.Execute(w, r.Host)
}

// serverWs handles websocket requests from the peer.
func serveWs(w http.ResponseWriter, r *http.Request) {