37 lines
556 B
Go
37 lines
556 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (worker *Worker) OperateHandler(cxt *gin.Context) {
|
|
log.Println(worker.Sensor())
|
|
}
|
|
|
|
func (worker *Worker) StatusHandler(cxt *gin.Context) {
|
|
|
|
}
|
|
|
|
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"))
|
|
|
|
}
|