🔧 **fix(model, controller): robust serialization for ChannelInfo & correct Vertex-AI key storage**

Summary
1. **model/channel.go**
   • Replaced the pointer-only `Value()` with a value-receiver implementation
   • GORM can now marshal both `ChannelInfo` and `*ChannelInfo`, eliminating
     `unsupported type model.ChannelInfo` runtime error.

2. **controller/channel.go**
   • Refactored `getVertexArrayKeys()` – every element is now
     - passed through `json.Marshal` when not already a string
     - trimmed & validated before insertion
   • Guarantees each service-account key is persisted as a **pure JSON string**
     instead of the previous `map[...]` dump.

Result
• Channel creation / update succeeds without SQL driver errors.
• Vertex-AI batch & multi-key uploads are stored in canonical JSON, ready for
  downstream SDKs to consume.
This commit is contained in:
t0ng7u
2025-07-07 01:31:41 +08:00
parent 870cdd5a56
commit f1856fe4d2
2 changed files with 14 additions and 4 deletions

View File

@@ -394,9 +394,19 @@ func getVertexArrayKeys(keys string) ([]string, error) {
}
cleanKeys := make([]string, 0, len(keyArray))
for _, key := range keyArray {
keyStr := fmt.Sprintf("%v", key)
var keyStr string
switch v := key.(type) {
case string:
keyStr = strings.TrimSpace(v)
default:
bytes, err := json.Marshal(v)
if err != nil {
return nil, fmt.Errorf("Vertex AI key JSON 编码失败: %w", err)
}
keyStr = string(bytes)
}
if keyStr != "" {
cleanKeys = append(cleanKeys, strings.TrimSpace(keyStr))
cleanKeys = append(cleanKeys, keyStr)
}
}
if len(cleanKeys) == 0 {

View File

@@ -53,8 +53,8 @@ type ChannelInfo struct {
}
// Value implements driver.Valuer interface
func (c *ChannelInfo) Value() (driver.Value, error) {
return common.EncodeJson(c)
func (c ChannelInfo) Value() (driver.Value, error) {
return common.EncodeJson(&c)
}
// Scan implements sql.Scanner interface