26 lines
431 B
Go
26 lines
431 B
Go
package handlers
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/fiber/v2/middleware/basicauth"
|
|
)
|
|
|
|
func Auth() fiber.Handler {
|
|
userpass := os.Getenv("USERPASS")
|
|
if userpass != "" {
|
|
userpass := strings.Split(userpass, ":")
|
|
return basicauth.New(basicauth.Config{
|
|
Users: map[string]string{
|
|
userpass[0]: userpass[1],
|
|
},
|
|
})
|
|
}
|
|
|
|
return func(c *fiber.Ctx) error {
|
|
return c.Next()
|
|
}
|
|
}
|