- golang-migrate embarqué via embed (db/migrations/*.sql), MigrateDatabase(url) au boot
- ids TEXT 32-hex avec CHECK ~ '^[0-9a-f]{32}$' ; operations idempotentes UNIQUE(device_id, operation_id)
- harness db/migrations_test.go (up → assertions schéma → down, skip si PG indisponible)
- DB dev fraîche vaultdrop_dev (la DB vaultdrop héberge un prototype V2 abandonné)
68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/vaultdrop/backend/config"
|
|
"github.com/vaultdrop/backend/db"
|
|
"github.com/vaultdrop/backend/handlers"
|
|
"github.com/vaultdrop/backend/pkg/auth"
|
|
)
|
|
|
|
func newRouter() *gin.Engine {
|
|
|
|
r := gin.Default()
|
|
|
|
public := r.Group("/api/v1")
|
|
{
|
|
public.GET("/health", handlers.Health)
|
|
public.POST("/devices", handlers.DevicesRegister)
|
|
}
|
|
|
|
protected := r.Group("/api/v1")
|
|
protected.Use(handlers.RequireDevice)
|
|
{
|
|
protected.GET("/files", handlers.FilesList)
|
|
protected.GET("/files/search", handlers.FilesSearch)
|
|
protected.GET("/files/:id", handlers.FilesGet)
|
|
protected.DELETE("/files/:id", handlers.FilesDelete)
|
|
protected.GET("/files/folders", handlers.FoldersList)
|
|
protected.POST("/files/upload", handlers.FilesUpload)
|
|
|
|
protected.POST("/ocr/jobs", handlers.OcrJobsCreate)
|
|
protected.GET("/ocr/jobs/:id", handlers.OcrJobsGet)
|
|
|
|
protected.POST("/sync/ops", handlers.SyncOpsPush)
|
|
protected.GET("/sync/permissions", handlers.SyncPermissionsGet)
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
func main() {
|
|
|
|
err, cfg := config.LoadApplicationConfig()
|
|
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
authManager, err := auth.NewManager(cfg.AuthSecret)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
handlers.Auth = authManager
|
|
|
|
if err := db.MigrateDatabase(cfg.DatabaseURL); err != nil {
|
|
log.Fatalf("migrations postgres: %v", err)
|
|
}
|
|
|
|
if err := newRouter().Run(fmt.Sprintf(":%d", cfg.Port)); err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
}
|