aboutsummaryrefslogtreecommitdiff
path: root/cmd/app/serve/serve.go
diff options
context:
space:
mode:
authorAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-10-07 01:06:55 +0300
committerAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-10-07 01:18:35 +0300
commit420e049415c8ec7f7a209a03110eecbe0c83e9e0 (patch)
treee93f7faf8c9704daa24c2653ca50b4f222fa2305 /cmd/app/serve/serve.go
parent0617918eb941c401b687d4a0dbc2a54c19e06fd1 (diff)
Мелкие правки
Diffstat (limited to 'cmd/app/serve/serve.go')
-rw-r--r--cmd/app/serve/serve.go51
1 files changed, 0 insertions, 51 deletions
diff --git a/cmd/app/serve/serve.go b/cmd/app/serve/serve.go
deleted file mode 100644
index 0609083..0000000
--- a/cmd/app/serve/serve.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package serve
-
-import (
- "github.com/labstack/echo/v4"
- "github.com/labstack/echo/v4/middleware"
- "github.com/ssoda/captcha"
- "github.com/uptrace/bun/extra/bundebug"
- "github.com/urfave/cli/v2"
- "sh.org.ru/pkg/config"
- "sh.org.ru/pkg/db"
- "sh.org.ru/pkg/handler"
- "sh.org.ru/static"
-)
-
-func Run(c *cli.Context) error {
- configFile := c.String("config")
- cfg, err := config.New(configFile)
- if err != nil {
- return err
- }
- db := db.New(cfg.DB)
- db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(cfg.Debug)))
-
- h := handler.Handler{DB: db}
-
- e := echo.New()
-
- e.HTTPErrorHandler = handler.ErrorHandler
-
- e.Use(middleware.Recover())
- e.Use(middleware.Logger())
-
- e.GET("/", h.Index)
- e.GET("/quote/:id", h.Quote)
- e.GET("/random", h.Random)
- e.GET("/add", h.AddQuote)
- e.POST("/add", h.AddQuotePost)
- e.GET("/add/success", h.AddQuoteSuccess)
- e.GET("/captcha/*", echo.WrapHandler(captcha.Server(400, 65)))
-
- func(g *echo.Group) {
- g.GET("/", h.Admin)
- g.POST("/action", h.AdminAction)
- }(e.Group("/admin", middleware.BasicAuth(func(u, p string, ctx echo.Context) (bool, error) {
- return cfg.Admins[u] == p, nil
- })))
-
- e.StaticFS("/", static.FS)
-
- return e.Start(cfg.Listen)
-}