- Go API server with PostgreSQL + Redis - AI floor replacement (OpenRouter Gemini) - Product database (10 brands, 3539 products) - Recommendation engine, calculator, articles - Redis async queue + worker pool - Hot product caching, brand view tracking - JWT auth, favorites, projects - Docker deployment ready Co-Authored-By: Claude <noreply@anthropic.com>
43 lines
942 B
Go
43 lines
942 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"floorvisualizer/internal/model"
|
|
"floorvisualizer/internal/repository"
|
|
)
|
|
|
|
func main() {
|
|
db, err := repository.Connect("postgres://postgres:dev123456@localhost:5432/floorvisualizer?sslmode=disable")
|
|
if err != nil {
|
|
log.Fatalf("Failed to connect: %v", err)
|
|
}
|
|
defer db.Close()
|
|
log.Println("Connected")
|
|
|
|
db.Exec("DELETE FROM articles")
|
|
db.Exec("ALTER SEQUENCE articles_id_seq RESTART WITH 1")
|
|
log.Println("Truncated")
|
|
|
|
data, err := os.ReadFile("data/articles.json")
|
|
if err != nil {
|
|
log.Fatalf("read json: %v", err)
|
|
}
|
|
|
|
var articles []model.Article
|
|
if err := json.Unmarshal(data, &articles); err != nil {
|
|
log.Fatalf("parse: %v", err)
|
|
}
|
|
|
|
if err := repository.InsertArticles(db, articles); err != nil {
|
|
log.Fatalf("insert: %v", err)
|
|
}
|
|
|
|
var count int
|
|
db.QueryRow("SELECT COUNT(*) FROM articles").Scan(&count)
|
|
fmt.Printf("Done! %d articles imported\n", count)
|
|
}
|