package main import ( "log" "os" "github.com/davecgh/go-spew/spew" "github.com/gin-gonic/gin" ) func (worker *Worker) OperateHandler(cxt *gin.Context) { //log.Println(worker.Sensor()) cmd := CommandType(cxt.PostForm("command")) worker.SendCommand(cmd) log.Println("SendCommand: ", cmd) } func (worker *Worker) StatusHandler(cxt *gin.Context) { cxt.Writer.WriteString(spew.Sprint(worker.Sensor())) } func main() { f, err := os.OpenFile("./log", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) if err != nil { panic(err) } log.SetOutput(f) engine := gin.Default() worker := NewWorker() engine.GET("/status", worker.StatusHandler) engine.POST("/operate", worker.OperateHandler) go worker.Run() log.Fatal(engine.Run(":15678")) }