47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package option
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/sagernet/sing/common/json/badoption"
|
|
)
|
|
|
|
type DurationSeconds time.Duration
|
|
|
|
func (d *DurationSeconds) UnmarshalJSON(b []byte) error {
|
|
var n int64
|
|
if err := json.Unmarshal(b, &n); err == nil {
|
|
*d = DurationSeconds(time.Duration(n) * time.Second)
|
|
return nil
|
|
}
|
|
var s string
|
|
if err := json.Unmarshal(b, &s); err == nil {
|
|
dur, err := time.ParseDuration(s)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*d = DurationSeconds(dur)
|
|
return nil
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (d DurationSeconds) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(time.Duration(d).String())
|
|
}
|
|
|
|
func (d DurationSeconds) Build() time.Duration {
|
|
return time.Duration(d)
|
|
}
|
|
|
|
type UserManagerOptions struct {
|
|
AuthServer string `json:"auth_server,omitempty"`
|
|
Timeout badoption.Duration `json:"timeout,omitempty"`
|
|
CacheTTL DurationSeconds `json:"cache_ttl,omitempty"`
|
|
RefreshInterval DurationSeconds `json:"refresh_interval,omitempty"`
|
|
ReportInterval DurationSeconds `json:"report_interval,omitempty"`
|
|
ReportTraffic bool `json:"report_traffic,omitempty"`
|
|
APISecret string `json:"api_secret,omitempty"`
|
|
APIListen string `json:"api_listen,omitempty"`
|
|
}
|