New rewrite with svelte and pocketbase

This commit is contained in:
zuma 2025-04-12 16:08:00 +02:00
parent 72bfc2ed89
commit 160617af60
95 changed files with 4402 additions and 0 deletions

52
backend/main.go Normal file
View file

@ -0,0 +1,52 @@
package main
import (
"os"
"log"
"github.com/pocketbase/pocketbase"
)
// Copied from https://github.com/s-petr/longhabit/blob/main/backend/main.go
// application holds the core application state and configuration.
type application struct {
pb *pocketbase.PocketBase
config appConfig
}
// appConfig holds the application's configuration settings.
type appConfig struct {
dbDir string
}
// newApplication creates and initializes a new application instance.
func newApplication() *application {
dbDir := getEnvOrDefault("DB_DIR", "pb_data")
return &application{
pb: pocketbase.NewWithConfig(pocketbase.Config{DefaultDataDir: dbDir}),
config: appConfig{
dbDir: dbDir,
},
}
}
func main() {
app := newApplication()
app.SetupCache()
app.SetupCrons()
app.SetupRoutes()
log.Fatal(app.pb.Start())
}
// getEnvOrDefault retrieves the value of an environment variable by key.
// If the environment variable is empty or not set, it returns the defaultValue.
func getEnvOrDefault(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
return defaultValue
}