Add Go rewrite with Postgres 17 and Dokploy Docker Compose

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
orohi
2026-07-27 08:21:21 +03:00
co-authored by Cursor
parent bac78dd3fc
commit 99a27f00be
67 changed files with 17864 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
// Command cleanup runs one pass of expired-share-link cleanup and exits; meant
// to be invoked periodically (cron, systemd timer, or the docker-compose
// "cleanup" service loop).
package main
import (
"context"
"log"
"time"
"github.com/joho/godotenv"
"amnezia-share/internal/config"
"amnezia-share/internal/db"
"amnezia-share/internal/panel"
"amnezia-share/internal/settings"
"amnezia-share/internal/share"
)
func main() {
_ = godotenv.Load()
cfg := config.Load()
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
pool, err := db.Connect(ctx, cfg.DatabaseURL)
if err != nil {
log.Fatalf("подключение к БД: %v", err)
}
defer pool.Close()
if err := db.Migrate(ctx, pool, cfg.MigrationsDir); err != nil {
log.Fatalf("миграции: %v", err)
}
st := &settings.Store{
Pool: pool,
EnvPanelURL: cfg.PanelURL,
EnvToken: cfg.PanelToken,
EnvLabelsJSON: cfg.ServerLabelsJSON,
}
pc := panel.New(cfg.HTTPBudget())
repo := share.New(pool)
runCtx, runCancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer runCancel()
res, err := repo.CleanupExpired(runCtx, pc, st)
if err != nil {
log.Fatalf("очистка не выполнена: %v", err)
}
log.Printf("очистка завершена: всего=%d (без конфигов=%d, снято с панели=%d), ошибок=%d",
res.Count, res.DBCount, res.PanelCount, len(res.Failures))
for _, f := range res.Failures {
log.Printf(" - %s", f)
}
}