2019-11-01 13:47:11 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2019-11-03 18:00:35 +00:00
|
|
|
"os"
|
2019-11-01 13:47:11 +00:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2019-11-03 18:00:35 +00:00
|
|
|
func (worker *Worker) OperateHandler(cxt *gin.Context) {
|
|
|
|
log.Println(worker.Sensor())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (worker *Worker) StatusHandler(cxt *gin.Context) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-11-01 13:47:11 +00:00
|
|
|
func main() {
|
2019-11-02 07:48:16 +00:00
|
|
|
|
2019-11-03 18:00:35 +00:00
|
|
|
f, err := os.OpenFile("./log", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
log.SetOutput(f)
|
2019-11-01 13:47:11 +00:00
|
|
|
engine := gin.Default()
|
|
|
|
|
2019-11-03 18:00:35 +00:00
|
|
|
worker := NewWorker()
|
|
|
|
|
|
|
|
engine.GET("/status", worker.StatusHandler)
|
|
|
|
engine.POST("/operate", worker.OperateHandler)
|
|
|
|
|
|
|
|
go worker.Run()
|
2019-11-01 13:47:11 +00:00
|
|
|
|
|
|
|
log.Fatal(engine.Run(":15678"))
|
2019-11-02 07:48:16 +00:00
|
|
|
|
2019-11-01 13:47:11 +00:00
|
|
|
}
|