Set up initial project structure with essential files and directories

This commit is contained in:
2025-12-14 21:20:28 +07:00
parent 9ae433aae9
commit cf7669191e
3 changed files with 166 additions and 0 deletions

61
cmd/pluto-api/main.go Normal file
View File

@@ -0,0 +1,61 @@
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"time"
"example.com/atlasos/internal/httpapp"
)
func main() {
addr := env("PLUTO_HTTP_ADDR", ":8080")
app, err := httpapp.New(httpapp.Config{
Addr: addr,
TemplatesDir: "web/templates",
StaticDir: "web/static",
})
if err != nil {
log.Fatalf("init app: %v", err)
}
srv := &http.Server{
Addr: addr,
Handler: app.Router(),
ReadHeaderTimeout: 5 * time.Second,
}
// Start server
go func() {
log.Printf("[pluto-api] listening on %s", addr)
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("listen: %v", err)
}
}()
// Graceful shutdown
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
<-stop
log.Printf("[pluto-api] shutdown requested")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
log.Printf("[pluto-api] shutdown error: %v", err)
} else {
log.Printf("[pluto-api] shutdown complete")
}
}
func env(key, def string) string {
if v := os.Getenv(key); v != "" {
return v
}
return def
}