package main import ( "embed" "encoding/base64" "log" "net/http" "os" "git.1e99.eu/1e99/passed/routes" "git.1e99.eu/1e99/passed/storage" ) //go:embed static/* var embedFS embed.FS func run() error { storage, err := storage.NewStore() if err != nil { return err } defer storage.Close() mux := http.NewServeMux() mux.Handle("GET /", routes.ServeFiles(embedFS, "static")) mux.Handle("POST /api/password", routes.CreatePassword(storage, 12*1024, base64.StdEncoding)) mux.Handle("GET /api/password/{id}", routes.GetPassword(storage, base64.StdEncoding)) address := os.Getenv("PASSED_ADDRESS") if address == "" { log.Printf("No PASSED_ADDRESS specified, defaulting to \":3000\"") address = ":3000" } err = http.ListenAndServe(address, routes.Logger(mux)) if err != nil { return err } return nil } func main() { err := run() if err != nil { log.Fatalf("%s", err) } }