-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (44 loc) · 1.03 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"embed"
"io/fs"
"log"
"net/http"
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/basicauth"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/monitor"
)
const (
ListenEnv = "LISTEN"
BasicAuthUserEnv = "BASIC_AUTH_USER"
BasicAuthPasswordEnv = "BASIC_AUTH_PASSWORD"
)
//go:embed site/*
var files embed.FS
func main() {
var err error
app := fiber.New(fiber.Config{})
app.Use(logger.New())
serveDir, err := fs.Sub(files, "site")
if err != nil {
log.Panic(err)
}
app.Use("/", filesystem.New(filesystem.Config{
Root: http.FS(serveDir),
PathPrefix: "",
Browse: true,
}))
app.Use("/stats", basicauth.New(basicauth.Config{
Users: map[string]string{
os.Getenv(BasicAuthUserEnv): os.Getenv(BasicAuthPasswordEnv),
},
}))
app.Use("/stats", monitor.New(monitor.ConfigDefault))
err = app.Listen(os.Getenv("LISTEN"))
if err != nil {
log.Panic(err)
}
}