go_echo_wol/main.go

56 lines
1.4 KiB
Go
Raw Normal View History

2023-09-02 11:47:53 +08:00
/*
* @Author: giaogiao giaogiao
* @Date: 2023-08-28 10:24:38
* @LastEditors: giaogiao giaogiao
* @LastEditTime: 2023-09-01 16:40:52
* @FilePath: \goweb\main.go
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
package main
import (
"embed"
"io/fs"
"log"
"net/http"
"os"
2023-09-02 16:05:31 +08:00
"goweb/controller"
2023-09-02 11:47:53 +08:00
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
//go:embed app
var embededFiles embed.FS
func getFileSystem(useOS bool) http.FileSystem {
if useOS {
log.Print("using live mode")
return http.FS(os.DirFS("app"))
}
log.Print("using embed mode")
fsys, err := fs.Sub(embededFiles, "app")
if err != nil {
panic(err)
}
return http.FS(fsys)
}
func main() {
e := echo.New()
useOS := len(os.Args) > 1 && os.Args[1] == "live"
assetHandler := http.FileServer(getFileSystem(useOS))
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{AllowOrigins: []string{"*"}, AllowMethods: []string{echo.GET, echo.HEAD, echo.PUT, echo.PATCH, echo.POST, echo.DELETE}}))
e.GET("/", echo.WrapHandler(assetHandler))
e.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", assetHandler)))
e.Use(middleware.Logger())
e.Use(middleware.Recover())
2023-09-08 10:34:03 +08:00
e.GET("/ws", controller.Hello)
e.GET("/mac/:mac", controller.Get_send_start)
2023-09-02 11:47:53 +08:00
e.Logger.Fatal(e.Start(":1323"))
}