edit: unique code shortlink ambil dari tabel shortcodes

This commit is contained in:
mario
2025-05-16 09:11:36 +07:00
parent d2ec8c0f07
commit 28339e855c
6 changed files with 384 additions and 34 deletions

View File

@@ -0,0 +1,54 @@
package main
import (
"flag"
"fmt"
"os"
"time"
"devone.aplikasi.web.id/gitea/mario/go-ohif-proxy/internal/api/repository"
"devone.aplikasi.web.id/gitea/mario/go-ohif-proxy/internal/database"
)
func main() {
/*
* HOW TO USE:
* `go run cmd/seed_shortcodes/seed_shortcodes.go -dsn="user:password@tcp(host_db:port)/nama_db_ohif_proxy"`
*
* Ini akan seeding DB dengan 3333 data (sesuai var count)
*/
// Parse command line flags
count := flag.Int("count", 3333, "Number of shortcodes to generate")
dsn := flag.String("dsn", "", "Database connection string (required)")
flag.Parse()
// Check if DSN is provided
if *dsn == "" {
fmt.Println("Error: Database connection string (DSN) is required")
fmt.Println("Usage: go run seed_shortcodes.go -dsn=user:password@tcp(localhost:3306)/database_name -count=1000")
os.Exit(1)
}
// Initialize database connection
err := database.Initialize(*dsn, 10, 5, 60*time.Minute)
if err != nil {
fmt.Printf("Failed to connect to database: %v\n", err)
os.Exit(1)
}
defer database.Close()
// Create a shortcode repository
shortCodeRepo := repository.NewShortCodeRepository()
// Seed the shortcodes
fmt.Printf("Seeding %d shortcodes...\n", *count)
err = shortCodeRepo.SeedShortCodes(*count)
if err != nil {
fmt.Printf("Error seeding shortcodes: %v\n", err)
os.Exit(1)
}
fmt.Println("Shortcode seeding completed successfully!")
}