From 121a23931fa58963b3bef0bf12f6227bb870cabe Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Fri, 16 Feb 2024 18:44:43 +0330 Subject: [PATCH] Change interval type --- config/config.go | 4 ++-- config/option.go | 12 +++++------- config/types.go | 25 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 config/types.go diff --git a/config/config.go b/config/config.go index 9c51dcd..f4d65d6 100644 --- a/config/config.go +++ b/config/config.go @@ -420,8 +420,8 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro URLTestOptions: option.URLTestOutboundOptions{ Outbounds: tags, URL: opt.ConnectionTestUrl, - Interval: opt.URLTestInterval, - IdleTimeout: opt.URLTestIdleTimeout, + Interval: option.Duration(opt.URLTestInterval.Duration()), + IdleTimeout: option.Duration(opt.URLTestIdleTimeout.Duration()), }, } diff --git a/config/option.go b/config/option.go index cc3793e..122f71a 100644 --- a/config/option.go +++ b/config/option.go @@ -1,8 +1,6 @@ package config import ( - "time" - "github.com/sagernet/sing-box/option" dns "github.com/sagernet/sing-dns" ) @@ -44,9 +42,9 @@ type InboundOptions struct { } type URLTestOptions struct { - ConnectionTestUrl string `json:"connection-test-url"` - URLTestInterval option.Duration `json:"url-test-interval"` - URLTestIdleTimeout option.Duration `json:"url-test-idle-timeout"` + ConnectionTestUrl string `json:"connection-test-url"` + URLTestInterval DurationInSeconds `json:"url-test-interval"` + URLTestIdleTimeout DurationInSeconds `json:"url-test-idle-timeout"` } type RouteOptions struct { @@ -94,8 +92,8 @@ func DefaultConfigOptions() *ConfigOptions { }, URLTestOptions: URLTestOptions{ ConnectionTestUrl: "http://cp.cloudflare.com/", - URLTestInterval: option.Duration(10 * time.Minute), - URLTestIdleTimeout: option.Duration(100 * time.Minute), + URLTestInterval: DurationInSeconds(600), + URLTestIdleTimeout: DurationInSeconds(6000), }, RouteOptions: RouteOptions{ ResolveDestination: false, diff --git a/config/types.go b/config/types.go new file mode 100644 index 0000000..9fe6cc5 --- /dev/null +++ b/config/types.go @@ -0,0 +1,25 @@ +package config + +import ( + "encoding/json" + "time" +) + +type DurationInSeconds int + +func (d DurationInSeconds) MarshalJSON() ([]byte, error) { + return json.Marshal(int64(d)) +} + +func (d *DurationInSeconds) UnmarshalJSON(bytes []byte) error { + var v int64 + if err := json.Unmarshal(bytes, &v); err != nil { + return err + } + *d = DurationInSeconds(v) + return nil +} + +func (d DurationInSeconds) Duration() time.Duration { + return time.Duration(d) * time.Second +}