123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package main
- import (
- "net/http"
- "os"
- "github.com/labstack/echo/v4"
- "github.com/labstack/echo/v4/middleware"
- )
- const tv_ip = "192.168.254.75"
- func homepage(c echo.Context) error {
- DebugInfo(tv_ip)
- //return c.String(http.StatusOK, "Hello World!")
- file, err := os.ReadFile("templates/index.html")
- if err != nil {
- return err
- }
- return c.HTMLBlob(http.StatusOK, file)
- }
- func tvcmd(c echo.Context) error {
- cmd := c.Param("cmd")
- switch cmd {
- case "power":
- PerformKey(tv_ip, "power")
- case "back":
- PerformKey(tv_ip, "back")
- case "home":
- PerformKey(tv_ip, "home")
- case "up":
- PerformKey(tv_ip, "up")
- case "left":
- PerformKey(tv_ip, "left")
- case "ok":
- PerformKey(tv_ip, "select")
- case "right":
- PerformKey(tv_ip, "right")
- case "down":
- PerformKey(tv_ip, "down")
- case "rewind":
- PerformKey(tv_ip, "rev")
- case "play-pause":
- PerformKey(tv_ip, "play")
- case "fast-forward":
- PerformKey(tv_ip, "fwd")
- /*case "star":
- // Unknown
- case "reload":
- // Unknown*/
- case "vol+":
- PerformKey(tv_ip, "volumeup")
- case "vol-":
- PerformKey(tv_ip, "volumedown")
- case "mute":
- PerformKey(tv_ip, "volumemute")
- default:
- c.Echo().Logger.Printf("Got '%v'\r\n", cmd)
- }
- return c.Redirect(http.StatusAccepted, "/")
- }
- func main() {
- e := echo.New()
- e.Use(middleware.Logger())
- e.Use(middleware.Static("static"))
- e.GET("/", homepage)
- e.GET("/tv/:cmd", tvcmd)
- e.Logger.Fatal(e.Start(":8000"))
- }
|