我正在嘗試將一些 golang 對象存儲在 SQL 數據庫中,并按如下方式實現了掃描器和值接口:func (attr *myStruct) Scan(src interface{}) error { switch v := src.(type) { case string: return json.Unmarshal([]byte(v), attr) case []byte: return json.Unmarshal(v, attr) } return fmt.Errorf("cannot convert %T to My struct", src)}//nolint:hugeParamfunc (attr mystruct) Value() (driver.Value, error) { return json.Marshal(attr)}有沒有一種方法可以通過Value()指針將參數傳遞給函數,因為在嘗試將數據轉換回我的結構時出現HugeParam錯誤,即傳遞給Value()函數的 attr 太大。任何建議表示贊賞,謝謝!更新:我試圖通過標記一個 nolint 來忽略巨大的參數來解決這個問題,但錯誤仍然存在。這是錯誤消息:golangci-lint run --deadline 300sfeedback-handler-test_1_fdc66eade9d0 | level=warning msg="[runner] The linter 'interfacer' is deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner. "feedback-handler-test_1_fdc66eade9d0 | level=warning msg="[runner/nolint] Found unknown linters in //nolint directives: gocritic:hugeparam"feedback-handler-test_1_fdc66eade9d0 | internal/app/domain/entity/feedbacks.go:61:7: hugeParam: attr is heavy (320 bytes); consider passing it by pointer (gocritic)
在 golang 中實現 Scan 和 Value 函數
ibeautiful
2022-12-19 19:26:05