From 7f1a471751f8041fe113f93c332bb8d1e313620c Mon Sep 17 00:00:00 2001 From: t0ng7u Date: Fri, 8 Aug 2025 03:52:07 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(model):=20replace?= =?UTF-8?q?=20gorm.io/datatypes=20with=20json.RawMessage=20for=20PrefillGr?= =?UTF-8?q?oup.Items?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Why: Avoid adding `gorm.io/datatypes` for a single field; the rest of the codebase does not use it, and using the standard library keeps dependencies lean. - What: - Switched `PrefillGroup.Items` from `datatypes.JSON` to `json.RawMessage`. - Updated imports in `model/prefill_group.go` to use `encoding/json` and removed the unused `gorm.io/datatypes`. - Preserved `gorm:"type:json"` so DB column behavior remains the same. - Impact: - API response/request shape for `items` remains unchanged (still JSON). - DB schema behavior is unchanged; GORM migration continues to handle the field as JSON. - No other references to `datatypes` exist; no `go.mod` changes needed. - Lints pass for the modified file. Files changed: - model/prefill_group.go No breaking changes. --- model/prefill_group.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/model/prefill_group.go b/model/prefill_group.go index 51e3e7f1..5db78cb2 100644 --- a/model/prefill_group.go +++ b/model/prefill_group.go @@ -1,9 +1,9 @@ package model import ( + "encoding/json" "one-api/common" - "gorm.io/datatypes" "gorm.io/gorm" ) @@ -18,7 +18,7 @@ type PrefillGroup struct { Id int `json:"id"` Name string `json:"name" gorm:"size:64;not null;uniqueIndex:uk_prefill_name,where:deleted_at IS NULL"` Type string `json:"type" gorm:"size:32;index;not null"` - Items datatypes.JSON `json:"items" gorm:"type:json"` + Items json.RawMessage `json:"items" gorm:"type:json"` Description string `json:"description,omitempty" gorm:"type:varchar(255)"` CreatedTime int64 `json:"created_time" gorm:"bigint"` UpdatedTime int64 `json:"updated_time" gorm:"bigint"`