我正在嘗試將一些 golang 對(duì)象存儲(chǔ)在 SQL 數(shù)據(jù)庫(kù)中,并按如下方式實(shí)現(xiàn)了掃描器和值接口: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()指針將參數(shù)傳遞給函數(shù),因?yàn)樵趪L試將數(shù)據(jù)轉(zhuǎn)換回我的結(jié)構(gòu)時(shí)出現(xiàn)HugeParam錯(cuò)誤,即傳遞給Value()函數(shù)的 attr 太大。任何建議表示贊賞,謝謝!更新:我試圖通過標(biāo)記一個(gè) nolint 來忽略巨大的參數(shù)來解決這個(gè)問題,但錯(cuò)誤仍然存在。這是錯(cuò)誤消息: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 中實(shí)現(xiàn) Scan 和 Value 函數(shù)
ibeautiful
2022-12-19 19:26:05