add basic auth

This commit is contained in:
Gianni Carafa
2023-11-02 20:57:44 +01:00
parent 3e3eebcdc2
commit c98e49f2b3
2 changed files with 14 additions and 1 deletions

View File

@@ -5,8 +5,10 @@ import (
"log"
"os"
"strconv"
"strings"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/basicauth"
)
func main() {
@@ -18,6 +20,16 @@ func main() {
},
)
userpass := os.Getenv("USERPASS")
if userpass != "" {
userpass := strings.Split(userpass, ":")
app.Use(basicauth.New(basicauth.Config{
Users: map[string]string{
userpass[0]: userpass[1],
},
}))
}
app.Get("/", handlers.Form)
app.Get("raw/*", handlers.Raw)
app.Get("api/*", handlers.Api)