mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-20 11:11:26 +00:00
🔨 Refactor method 'UnmarshalJSON' of 'option[T]'
This commit is contained in:
parent
2e6110e54a
commit
d392d4a787
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"url": "https://example.com",
|
"url": "https://example.com",
|
||||||
"no_proxy_check": false,
|
"no_proxy_check": true,
|
||||||
"timeout": 10000,
|
"timeout": 10000,
|
||||||
"dodos_count": 50,
|
"dodos_count": 50,
|
||||||
"request_count": 1000,
|
"request_count": 1000,
|
||||||
|
@ -65,12 +65,17 @@ func (o *option[T]) SetNone() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *option[T]) UnmarshalJSON(data []byte) error {
|
func (o *option[T]) UnmarshalJSON(data []byte) error {
|
||||||
if string(data) == "null" {
|
if string(data) == "null" || len(data) == 0 {
|
||||||
o.none = true
|
o.SetNone()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(data, &o.value); err != nil {
|
||||||
|
o.SetNone()
|
||||||
|
return err
|
||||||
|
}
|
||||||
o.none = false
|
o.none = false
|
||||||
return json.Unmarshal(data, &o.value)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOption[T NonNilT](value T) *option[T] {
|
func NewOption[T NonNilT](value T) *option[T] {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user