godash/main.go

58 lines
1.4 KiB
Go
Raw Normal View History

2024-03-12 15:49:08 +01:00
package main
import (
"fmt"
"log/slog"
"net/http"
"os"
"strings"
"github.com/labstack/echo-contrib/session"
2024-03-12 15:49:08 +01:00
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/quasoft/memstore"
2024-03-12 15:49:08 +01:00
"github.com/r3labs/sse/v2"
"gitlab.unjx.de/flohoss/godash/handlers"
"gitlab.unjx.de/flohoss/godash/internal/env"
"gitlab.unjx.de/flohoss/godash/services"
)
func main() {
env, err := env.Parse()
if err != nil {
slog.Error("cannot parse environment variables", "err", err)
os.Exit(1)
}
e := echo.New()
e.HideBanner = true
e.HidePort = true
e.Use(middleware.Recover())
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
Skipper: func(c echo.Context) bool {
return strings.Contains(c.Path(), "sse") || strings.Contains(c.Path(), "sign")
2024-03-12 15:49:08 +01:00
},
}))
if env.LogtoEndpoint != "" {
e.Use(session.Middleware(memstore.NewMemStore([]byte(env.SessionKey))))
}
2024-03-12 15:49:08 +01:00
sse := sse.New()
sse.AutoReplay = false
s := services.NewSystemService(sse)
2024-03-15 18:56:32 +01:00
w := services.NewWeatherService(sse, env)
2024-03-12 15:49:08 +01:00
b := services.NewBookmarkService()
2024-03-18 21:54:35 +01:00
authHandler := handlers.NewAuthHandler(env)
2024-03-25 20:31:51 +01:00
appHandler := handlers.NewAppHandler(env, authHandler, s, w, b)
2024-03-18 21:54:35 +01:00
handlers.SetupRoutes(e, sse, appHandler, authHandler)
2024-03-12 15:49:08 +01:00
2024-03-18 21:54:35 +01:00
slog.Info("starting server", "url", env.PublicUrl)
2024-03-19 11:36:09 +01:00
if err := e.Start(fmt.Sprintf("0.0.0.0:%d", env.Port)); err != http.ErrServerClosed {
2024-03-12 15:49:08 +01:00
slog.Error("cannot start server", "err", err)
os.Exit(1)
}
}