Change interval type

This commit is contained in:
problematicconsumer
2024-02-16 18:44:43 +03:30
parent ad015a359e
commit 121a23931f
3 changed files with 32 additions and 9 deletions

View File

@@ -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()),
},
}

View File

@@ -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,

25
config/types.go Normal file
View File

@@ -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
}