41 lines
966 B
Go
41 lines
966 B
Go
package main
|
|
|
|
import (
|
|
"cmp"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"lodge/internal/server"
|
|
)
|
|
|
|
func main() {
|
|
database := cmp.Or(os.Getenv("LODGE_DB"), "/app/storage/lodge.db")
|
|
if err := os.MkdirAll(filepath.Dir(database), 0o700); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
store, err := server.OpenStore(database)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
config := server.Config{
|
|
AdminToken: os.Getenv("ADMIN_TOKEN"),
|
|
PublicURL: os.Getenv("PUBLIC_URL"),
|
|
StaticDir: cmp.Or(os.Getenv("STATIC_DIR"), "/app/static"),
|
|
ClientsDir: cmp.Or(os.Getenv("CLIENTS_DIR"), "/app/dl"),
|
|
}
|
|
if config.AdminToken == "" {
|
|
log.Print("ADMIN_TOKEN is empty: no machine can be added until it is set")
|
|
}
|
|
httpServer := &http.Server{
|
|
Addr: cmp.Or(os.Getenv("LISTEN"), ":8080"),
|
|
Handler: server.New(store, config),
|
|
ReadHeaderTimeout: 10 * time.Second,
|
|
}
|
|
log.Printf("listening on %s", httpServer.Addr)
|
|
log.Fatal(httpServer.ListenAndServe())
|
|
}
|