-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (33 loc) · 733 Bytes
/
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
package main
import (
"embed"
"errors"
"io/fs"
"log"
"net"
"net/http"
"os"
"github.com/bavix/boxpacker3-ui/internal/app"
)
//go:embed public
var publicFiles embed.FS
func main() {
htmlContent, err := fs.Sub(publicFiles, "public")
if err != nil {
log.Fatal(err)
}
http.Handle("/", http.FileServer(http.FS(htmlContent)))
http.HandleFunc("/bp3", app.Bp3Handle)
http.HandleFunc("/bp3boxes", app.Bp3DefaultBoxesHandle)
host, _ := os.LookupEnv("HOST")
port, ok := os.LookupEnv("PORT")
if !ok {
port = "8080"
}
addr := net.JoinHostPort(host, port)
log.Printf("Listening on %s...\n", addr)
err = http.ListenAndServe(addr, nil)
if err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
}