package main import ( "strings" "github.com/spf13/viper" "gopkg.in/macaron.v1" ) func upsPage(ctx *macaron.Context) { ctx.Data["host"] = viper.GetString("UpsHost") ctx.Data["upsname"] = viper.GetString("UpsName") ctx.Data["username"] = viper.GetString("UpsUsername") ctx.Data["password"] = viper.GetString("UpsPassword") // if ups == nil { // ctx.Data["serverstatus"] = "Disconnected" // ctx.Data["upsstatus"] = "unknown" // } else { ctx.Data["serverstatus"] = "Connected" ctx.Data["upsstatus"] = upsVars["ups.status"].Value ctx.Data["upsmfr"] = upsVars["device.mfr"].Value ctx.Data["upsmodel"] = upsVars["device.model"].Value ctx.Data["upsserial"] = upsVars["device.serial"].Value // } ctx.HTML(200, "ups") } type UPSPostForm struct { Host string `form:"host" binding:"Required"` UpsName string `form:"upsname" binding:"Required"` Username string `form:"username" binding:"Required"` Password string `form:"password" binding:"Required"` } func upsPost(ctx *macaron.Context, f UPSPostForm) { viper.Set("UpsHost", strings.ToLower(strings.TrimSpace(f.Host))) viper.Set("UpsName", strings.TrimSpace(f.UpsName)) viper.Set("UpsUsername", strings.TrimSpace(f.Username)) viper.Set("UpsPassword", f.Password) viper.WriteConfig() UpsReconfigure() upsPage(ctx) }