- library.New now creates BOOKS_DIR (MkdirAll) on startup so uploads don't fail when the directory is missing on a fresh bind mount - uploadSubmit logs the underlying OS error on save/write failures - README: document docker-compose deployment, container UID/GID (100/101) for bind-mounted ./data permissions, and running the admin CLI via docker compose exec Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
45 lines
864 B
Go
45 lines
864 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/arnef/ebooks/internal/library"
|
|
"github.com/arnef/ebooks/internal/users"
|
|
"github.com/arnef/ebooks/internal/web"
|
|
)
|
|
|
|
func main() {
|
|
booksDir := getenv("BOOKS_DIR", "books")
|
|
addr := getenv("ADDR", ":8080")
|
|
usersDB := getenv("USERS_DB", "users.db")
|
|
|
|
store, err := users.Open(usersDB)
|
|
if err != nil {
|
|
log.Fatalf("users db: %v", err)
|
|
}
|
|
defer store.Close()
|
|
|
|
lib, err := library.New(booksDir)
|
|
if err != nil {
|
|
log.Fatalf("books dir: %v", err)
|
|
}
|
|
h := web.NewHandler(lib, store)
|
|
|
|
mux := http.NewServeMux()
|
|
h.RegisterRoutes(mux)
|
|
|
|
log.Printf("ebooks server listening on %s (books dir: %s)", addr, booksDir)
|
|
if err := http.ListenAndServe(addr, mux); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func getenv(key, fallback string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return fallback
|
|
}
|