feat: add SQLite persistence and REST API for temporary whitelisting
- Migrate IP-based temporary whitelisting from file to SQLite storage - Add REST API endpoints for managing temporary and permanent whitelists - Create `.env.example` with required environment variables - Document API endpoints in README.md and docs/api.md - Add new dependency `modernc.org/sqlite` for SQLite support - Update deployment and security documentation
This commit is contained in:
8
main.go
8
main.go
@@ -7,15 +7,14 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := loadConfig()
|
||||
|
||||
// Set up structured logging
|
||||
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, nil)))
|
||||
|
||||
// Initialize database
|
||||
db, err := InitDB(cfg.DBPath)
|
||||
if err != nil {
|
||||
slog.Error("failed to init database", "error", err)
|
||||
@@ -23,10 +22,8 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
// Start background cleanup of expired temp entries
|
||||
go cleanupLoop(db, cfg.CleanupInterval)
|
||||
|
||||
// Setup HTTP server
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/auth", authHandler(cfg, db))
|
||||
mux.HandleFunc("/api/whitelist/temp", whitelistTempHandler(cfg, db))
|
||||
@@ -40,7 +37,6 @@ func main() {
|
||||
server := &http.Server{
|
||||
Addr: ":" + cfg.Port,
|
||||
Handler: mux,
|
||||
// timeouts as before
|
||||
}
|
||||
|
||||
go func() {
|
||||
@@ -59,4 +55,4 @@ func main() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
server.Shutdown(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user