first commit

This commit is contained in:
2026-07-09 22:16:19 +02:00
commit 869749bb01
34 changed files with 3204 additions and 0 deletions

52
main.go Normal file
View File

@@ -0,0 +1,52 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2026 Bryan Joshua Pedini
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
)
var APP_VERSION string = "latest"
var COMMIT_ID string = "undefined"
var ws *WebServer
func main() {
// Initialize the WebService structure (parses env config, sets up logger)
ws = new(WebServer)
ws.Initialize()
// Drop root privileges before any listener, goroutine, or DB connection
dropPrivileges(ws.Logger, ws.Config.PUID, ws.Config.PGID)
// Create a channel to receive the OS signals
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM)
// Open the MySQL pool (after the privilege drop) and ping it
ws.DB = OpenDB(ws.Logger, ws.Config.MySQLDSN)
ws.Store = NewStore(ws.DB, ws.Config.TablePrefix)
// Start the WebService in a separate goroutine
go ws.Start()
// Wait for a signal
<-sc
fmt.Println("Shutting down...")
// Create a context with a timeout for graceful shutdown
shCtx, shCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer shCancel()
// Shutdown the HTTP server
err := ws.HTTPServer.Shutdown(shCtx)
if err != nil {
fmt.Printf("Server shutdown error: %s", err)
os.Exit(1)
}
}