🔨 Refactor method 'UnmarshalJSON' of 'option[T]'

This commit is contained in:
aykhans committed 2024-11-28 04:20:01 +04:00
1 parent 2e6110e54a
commit d392d4a787
2 files changed
+9 -4

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"method": "GET",
"url": "https://example.com",
"no_proxy_check": false,
"no_proxy_check": true,
"timeout": 10000,
"dodos_count": 50,
"request_count": 1000,
+8 -3
View File
@@ -65,12 +65,17 @@ func (o *option[T]) SetNone() {
}
func (o *option[T]) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
o.none = true
if string(data) == "null" || len(data) == 0 {
o.SetNone()
return nil
}
if err := json.Unmarshal(data, &o.value); err != nil {
o.SetNone()
return err
}
o.none = false
return json.Unmarshal(data, &o.value)
return nil
}
func NewOption[T NonNilT](value T) *option[T] {