New rewrite with svelte and pocketbase
This commit is contained in:
parent
72bfc2ed89
commit
160617af60
95 changed files with 4402 additions and 0 deletions
52
backend/main.go
Normal file
52
backend/main.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue