From d392d4a78759420aa2fa78e378dfedb7dafe2110 Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Thu, 28 Nov 2024 04:20:01 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Refactor=20method=20'UnmarshalJS?= =?UTF-8?q?ON'=20of=20'option[T]'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json | 2 +- utils/types.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/config.json b/config.json index 217392f..202f0ac 100644 --- a/config.json +++ b/config.json @@ -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, diff --git a/utils/types.go b/utils/types.go index 577e4de..92f65b9 100644 --- a/utils/types.go +++ b/utils/types.go @@ -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] {