sport_rec_demo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

62 lines
1.4 KiB

package main
import (
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/spf13/cobra"
"log"
"os"
)
var listenAddr = ":3000"
var rootCmd = &cobra.Command{
Use: "sport_rec",
Short: "Sport Recognition Demo",
Long: "Sport Recognition Demo",
}
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVarP(&listenAddr, "listen", "L", ":3000", "Service listen address")
rootCmd.PersistentFlags().BoolVarP(&fakeClient, "fake", "F", false, "Fake HTP client instead of pushing")
rootCmd.AddCommand(serveCmd)
}
func initConfig() {
}
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Run service",
Run: func(cmd *cobra.Command, args []string) {
app := fiber.New()
app.Use(func(c *fiber.Ctx) error {
log.Println("<-", c.IP(), c.Method(), c.Request().URI())
return c.Next()
})
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})
app.Post("/api/v1/setScene", setScene)
app.Post("/api/v1/setTestCmd", setTestCmd)
// app.Post("/api/v1/eventHandle")
app.Post("/api/v1/areaConfig", setAreaConfig)
app.Get("/api/v1/areaConfig", getAreaConfig)
app.Post("/api/v1/stopScene", stopScene)
app.Get("/api/v1/stopScene", stopScene)
app.Get("/api/v1/getStatus", getStatus)
app.Get("/api/v1/getTestStatus", getStatus)
log.Fatal(app.Listen(listenAddr))
},
}
func main() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}