-
Notifications
You must be signed in to change notification settings - Fork 0
Remove Echo framework, upgrade to Go 1.24 and PocketBase v0.36.2 #877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,12 +16,10 @@ package cmd | |
|
|
||
| import ( | ||
| "io/fs" | ||
| "net/http" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/kindlyops/vbs/embeddy" | ||
| "github.com/labstack/echo/v5" | ||
| "github.com/muesli/coral" | ||
| "github.com/pocketbase/pocketbase" | ||
| "github.com/pocketbase/pocketbase/apis" | ||
|
|
@@ -52,54 +50,33 @@ func flyServer(cmd *coral.Command, args []string) { | |
| } | ||
|
|
||
| log.Debug().Msgf("running pocketbase with data dir %s\n", configDir) | ||
| app := pocketbase.NewWithConfig(&pocketbase.Config{ | ||
| app := pocketbase.NewWithConfig(pocketbase.Config{ | ||
| DefaultDataDir: configDir, | ||
| }) | ||
|
|
||
| migrationsDir := "" // default to "pb_migrations" (for js) and "migrations" (for go) | ||
|
|
||
| // register the `migrate` command | ||
| migratecmd.MustRegister(app, app.RootCmd, &migratecmd.Options{ | ||
| migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{ | ||
| TemplateLang: migratecmd.TemplateLangGo, // or migratecmd.TemplateLangJS | ||
| Dir: migrationsDir, | ||
| Automigrate: true, | ||
| }) | ||
|
|
||
| app.OnBeforeServe().Add(func(e *core.ServeEvent) error { | ||
| app.OnServe().BindFunc(func(e *core.ServeEvent) error { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
| public, err := fs.Sub(embeddy.GetNextFS(), "public") | ||
| if err != nil { | ||
| log.Fatal().Err(err).Msg("Could not access embedded public directory") | ||
| } | ||
| assetHandler := http.FileServer(http.FS(public)) | ||
| e.Router.AddRoute(echo.Route{ | ||
| Method: http.MethodGet, | ||
| Path: "/*", | ||
| Handler: echo.WrapHandler(assetHandler), | ||
| Middlewares: []echo.MiddlewareFunc{ | ||
| apis.ActivityLogger(app), | ||
| //apis.RequireAdminAuth(), | ||
| }, | ||
| }) | ||
|
|
||
| e.Router.AddRoute(echo.Route{ | ||
| Method: http.MethodPost, | ||
| Path: "/api/switcher/*", | ||
| Middlewares: []echo.MiddlewareFunc{ | ||
| apis.ActivityLogger(app), | ||
| }, | ||
| Handler: echo.WrapHandler(&Switcher{}), | ||
| }) | ||
|
|
||
| e.Router.AddRoute(echo.Route{ | ||
| Method: http.MethodPost, | ||
| Path: "/api/light/*", | ||
| Middlewares: []echo.MiddlewareFunc{ | ||
| apis.ActivityLogger(app), | ||
| }, | ||
| Handler: echo.WrapHandler(&Lighting{}), | ||
| }) | ||
|
|
||
| return nil | ||
|
|
||
| // Serve static files | ||
| e.Router.GET("/*", apis.Static(public, true)) | ||
|
|
||
| // Custom API routes | ||
| e.Router.POST("/api/switcher/*", apis.WrapStdHandler(&Switcher{})) | ||
| e.Router.POST("/api/light/*", apis.WrapStdHandler(&Lighting{})) | ||
|
|
||
| return e.Next() | ||
| }) | ||
|
|
||
| if err := app.Start(); err != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,6 @@ import ( | |
|
|
||
| "github.com/hypebeast/go-osc/osc" | ||
| "github.com/kindlyops/vbs/embeddy" | ||
| "github.com/labstack/echo/v5" | ||
| "github.com/muesli/coral" | ||
| "github.com/rs/zerolog/log" | ||
| "github.com/spf13/viper" | ||
|
|
@@ -53,14 +52,21 @@ func lightingBridge(cmd *coral.Command, args []string) { | |
| assetHandler := http.FileServer(http.FS(public)) | ||
|
|
||
| log.Debug().Msgf("Starting HTTP server at: http://%s\n", listenAddr) | ||
| e := echo.New() | ||
| e.GET("/*", echo.WrapHandler(assetHandler)) | ||
| e.POST("/api/switcher/*", echo.WrapHandler(&Switcher{})) | ||
| e.POST("/api/light/*", echo.WrapHandler(&Lighting{})) | ||
| err = e.Start(listenAddr) | ||
|
|
||
| mux := http.NewServeMux() | ||
| mux.Handle("/", assetHandler) | ||
| mux.Handle("/api/switcher/", &Switcher{}) | ||
| mux.Handle("/api/light/", &Lighting{}) | ||
|
|
||
| server := &http.Server{ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
| Addr: listenAddr, | ||
| Handler: mux, | ||
| } | ||
|
|
||
| err = server.ListenAndServe() | ||
|
|
||
| if err != nil { | ||
| log.Error().Err(err).Msg("error from echo.Start") | ||
| log.Error().Err(err).Msg("error from http server") | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,16 +2,26 @@ package embeddy | |
|
|
||
| import ( | ||
| "embed" | ||
|
|
||
| "github.com/labstack/echo/v5" | ||
| "fmt" | ||
| "io/fs" | ||
| ) | ||
|
|
||
| //go:embed public | ||
| var publicDir embed.FS | ||
|
|
||
| // DistDirFS contains the embedded public directory files (without the "public" prefix) | ||
| var DistDirFS = echo.MustSubFS(publicDir, "public") | ||
| var DistDirFS = MustSubFS(publicDir, "public") | ||
|
|
||
| func GetNextFS() embed.FS { | ||
| return publicDir | ||
| } | ||
|
|
||
| // MustSubFS returns an fs.FS corresponding to the subtree rooted at dir. | ||
| // It panics if there's an error. | ||
| func MustSubFS(fsys fs.FS, dir string) fs.FS { | ||
| sub, err := fs.Sub(fsys, dir) | ||
| if err != nil { | ||
| panic(fmt.Errorf("failed to create sub FS: %w", err)) | ||
| } | ||
| return sub | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
pocketbase.Config is missing fields HideStartBanner, DefaultDev, DefaultEncryptionEnv, DefaultQueryTimeout, DataMaxOpenConns, DataMaxIdleConns, AuxMaxOpenConns, AuxMaxIdleConns, DBConnect (exhaustruct)