This commit is contained in:
Sakurasan
2024-09-14 00:31:07 +08:00
parent 7979102880
commit eef24913e0

View File

@@ -2,14 +2,11 @@ package store
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"log" "log"
"opencatd-open/pkg/vertexai" "opencatd-open/pkg/vertexai"
"os" "os"
"time" "time"
"gorm.io/gorm"
) )
func init() { func init() {
@@ -27,15 +24,9 @@ func init() {
Key: vertex_auth, Key: vertex_auth,
ApiSecret: vertex_auth, ApiSecret: vertex_auth,
} }
if err := db.Table("keys").Where("name = ?", Vertex.ProjectID).Find(&key).Error; err != nil { if err := db.Where("name = ?", Vertex.ProjectID).FirstOrCreate(&key).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { log.Fatalln(fmt.Errorf("import vertex_auth json error: %w", err))
if err := db.Create(&key).Error; err != nil { return
log.Fatalln(fmt.Errorf("import vertex_auth json error: %w", err))
}
} else {
log.Fatalln(fmt.Errorf("import vertex_auth json error: %w", err))
return
}
} }
} }
LoadKeysCache() LoadKeysCache()