move auth and favicon form main to handlers, linting

This commit is contained in:
ladddder
2023-12-05 16:00:31 +01:00
parent 692b2a5d17
commit f437bcabf3
13 changed files with 249 additions and 226 deletions

View File

@@ -6,7 +6,6 @@ import (
"html/template"
"log"
"os"
"strings"
"ladder/handlers"
"ladder/internal/cli"
@@ -14,14 +13,9 @@ import (
"github.com/akamensky/argparse"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/basicauth"
"github.com/gofiber/fiber/v2/middleware/favicon"
"github.com/gofiber/template/html/v2"
)
//go:embed favicon.ico
var faviconData string
//go:embed styles.css
var cssData embed.FS
@@ -151,23 +145,8 @@ func main() {
},
)
// TODO: move to cmd/auth.go
userpass := os.Getenv("USERPASS")
if userpass != "" {
userpass := strings.Split(userpass, ":")
app.Use(basicauth.New(basicauth.Config{
Users: map[string]string{
userpass[0]: userpass[1],
},
}))
}
// TODO: move to handlers/favicon.go
app.Use(favicon.New(favicon.Config{
Data: []byte(faviconData),
URL: "/favicon.ico",
}))
app.Use(handlers.Auth())
app.Use(handlers.Favicon())
if os.Getenv("NOLOGS") != "true" {
app.Use(func(c *fiber.Ctx) error {