mirror of https://github.com/rclone/rclone.git
config: make parsing of duration value of global flags consistent (more)
This commit is contained in:
parent
0bcf2ed4e4
commit
4fadba9bcb
|
@ -55,7 +55,7 @@ type Options struct {
|
||||||
Compare CompareOpt
|
Compare CompareOpt
|
||||||
CompareFlag string
|
CompareFlag string
|
||||||
DebugName string
|
DebugName string
|
||||||
MaxLock time.Duration
|
MaxLock fs.Duration
|
||||||
ConflictResolve Prefer
|
ConflictResolve Prefer
|
||||||
ConflictLoser ConflictLoserAction
|
ConflictLoser ConflictLoserAction
|
||||||
ConflictSuffixFlag string
|
ConflictSuffixFlag string
|
||||||
|
@ -146,7 +146,7 @@ func init() {
|
||||||
flags.BoolVarP(cmdFlags, &Opt.Compare.NoSlowHash, "no-slow-hash", "", Opt.Compare.NoSlowHash, "Ignore listing checksums only on backends where they are slow", "")
|
flags.BoolVarP(cmdFlags, &Opt.Compare.NoSlowHash, "no-slow-hash", "", Opt.Compare.NoSlowHash, "Ignore listing checksums only on backends where they are slow", "")
|
||||||
flags.BoolVarP(cmdFlags, &Opt.Compare.SlowHashSyncOnly, "slow-hash-sync-only", "", Opt.Compare.SlowHashSyncOnly, "Ignore slow checksums for listings and deltas, but still consider them during sync calls.", "")
|
flags.BoolVarP(cmdFlags, &Opt.Compare.SlowHashSyncOnly, "slow-hash-sync-only", "", Opt.Compare.SlowHashSyncOnly, "Ignore slow checksums for listings and deltas, but still consider them during sync calls.", "")
|
||||||
flags.BoolVarP(cmdFlags, &Opt.Compare.DownloadHash, "download-hash", "", Opt.Compare.DownloadHash, "Compute hash by downloading when otherwise unavailable. (warning: may be slow and use lots of data!)", "")
|
flags.BoolVarP(cmdFlags, &Opt.Compare.DownloadHash, "download-hash", "", Opt.Compare.DownloadHash, "Compute hash by downloading when otherwise unavailable. (warning: may be slow and use lots of data!)", "")
|
||||||
flags.DurationVarP(cmdFlags, &Opt.MaxLock, "max-lock", "", Opt.MaxLock, "Consider lock files older than this to be expired (default: 0 (never expire)) (minimum: 2m)", "")
|
flags.FVarP(cmdFlags, &Opt.MaxLock, "max-lock", "", "Consider lock files older than this to be expired (default: 0 (never expire)) (minimum: 2m)", "")
|
||||||
flags.FVarP(cmdFlags, &Opt.ConflictResolve, "conflict-resolve", "", "Automatically resolve conflicts by preferring the version that is: "+ConflictResolveList+" (default: none)", "")
|
flags.FVarP(cmdFlags, &Opt.ConflictResolve, "conflict-resolve", "", "Automatically resolve conflicts by preferring the version that is: "+ConflictResolveList+" (default: none)", "")
|
||||||
flags.FVarP(cmdFlags, &Opt.ConflictLoser, "conflict-loser", "", "Action to take on the loser of a sync conflict (when there is a winner) or on both files (when there is no winner): "+ConflictLoserList+" (default: num)", "")
|
flags.FVarP(cmdFlags, &Opt.ConflictLoser, "conflict-loser", "", "Action to take on the loser of a sync conflict (when there is a winner) or on both files (when there is no winner): "+ConflictLoserList+" (default: num)", "")
|
||||||
flags.StringVarP(cmdFlags, &Opt.ConflictSuffixFlag, "conflict-suffix", "", Opt.ConflictSuffixFlag, "Suffix to use when renaming a --conflict-loser. Can be either one string or two comma-separated strings to assign different suffixes to Path1/Path2. (default: 'conflict')", "")
|
flags.StringVarP(cmdFlags, &Opt.ConflictSuffixFlag, "conflict-suffix", "", Opt.ConflictSuffixFlag, "Suffix to use when renaming a --conflict-loser. Can be either one string or two comma-separated strings to assign different suffixes to Path1/Path2. (default: 'conflict')", "")
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"github.com/rclone/rclone/lib/terminal"
|
"github.com/rclone/rclone/lib/terminal"
|
||||||
)
|
)
|
||||||
|
|
||||||
const basicallyforever = 200 * 365 * 24 * time.Hour
|
const basicallyforever = fs.Duration(200 * 365 * 24 * time.Hour)
|
||||||
|
|
||||||
var stopRenewal func()
|
var stopRenewal func()
|
||||||
|
|
||||||
|
@ -66,9 +66,9 @@ func (b *bisyncRun) removeLockFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bisyncRun) setLockFileExpiration() {
|
func (b *bisyncRun) setLockFileExpiration() {
|
||||||
if b.opt.MaxLock > 0 && b.opt.MaxLock < 2*time.Minute {
|
if b.opt.MaxLock > 0 && b.opt.MaxLock < fs.Duration(2*time.Minute) {
|
||||||
fs.Logf(nil, Color(terminal.YellowFg, "--max-lock cannot be shorter than 2 minutes (unless 0.) Changing --max-lock from %v to %v"), b.opt.MaxLock, 2*time.Minute)
|
fs.Logf(nil, Color(terminal.YellowFg, "--max-lock cannot be shorter than 2 minutes (unless 0.) Changing --max-lock from %v to %v"), b.opt.MaxLock, 2*time.Minute)
|
||||||
b.opt.MaxLock = 2 * time.Minute
|
b.opt.MaxLock = fs.Duration(2 * time.Minute)
|
||||||
} else if b.opt.MaxLock <= 0 {
|
} else if b.opt.MaxLock <= 0 {
|
||||||
b.opt.MaxLock = basicallyforever
|
b.opt.MaxLock = basicallyforever
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func (b *bisyncRun) renewLockFile() {
|
||||||
data.Session = b.basePath
|
data.Session = b.basePath
|
||||||
data.PID = strconv.Itoa(os.Getpid())
|
data.PID = strconv.Itoa(os.Getpid())
|
||||||
data.TimeRenewed = time.Now()
|
data.TimeRenewed = time.Now()
|
||||||
data.TimeExpires = time.Now().Add(b.opt.MaxLock)
|
data.TimeExpires = time.Now().Add(time.Duration(b.opt.MaxLock))
|
||||||
|
|
||||||
// save data file
|
// save data file
|
||||||
df, err := os.Create(b.lockFile)
|
df, err := os.Create(b.lockFile)
|
||||||
|
@ -131,7 +131,7 @@ func (b *bisyncRun) startLockRenewal() func() {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
ticker := time.NewTicker(b.opt.MaxLock - time.Minute)
|
ticker := time.NewTicker(time.Duration(b.opt.MaxLock) - time.Minute)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
|
|
@ -14,13 +14,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
pollInterval = 10 * time.Second
|
pollInterval = fs.Duration(10 * time.Second)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
test.Command.AddCommand(commandDefinition)
|
test.Command.AddCommand(commandDefinition)
|
||||||
cmdFlags := commandDefinition.Flags()
|
cmdFlags := commandDefinition.Flags()
|
||||||
flags.DurationVarP(cmdFlags, &pollInterval, "poll-interval", "", pollInterval, "Time to wait between polling for changes", "")
|
flags.FVarP(cmdFlags, &pollInterval, "poll-interval", "", "Time to wait between polling for changes", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
var commandDefinition = &cobra.Command{
|
var commandDefinition = &cobra.Command{
|
||||||
|
@ -39,7 +39,7 @@ var commandDefinition = &cobra.Command{
|
||||||
if do := features.ChangeNotify; do != nil {
|
if do := features.ChangeNotify; do != nil {
|
||||||
pollChan := make(chan time.Duration)
|
pollChan := make(chan time.Duration)
|
||||||
do(ctx, changeNotify, pollChan)
|
do(ctx, changeNotify, pollChan)
|
||||||
pollChan <- pollInterval
|
pollChan <- time.Duration(pollInterval)
|
||||||
fs.Logf(nil, "Waiting for changes, polling every %v", pollInterval)
|
fs.Logf(nil, "Waiting for changes, polling every %v", pollInterval)
|
||||||
} else {
|
} else {
|
||||||
return errors.New("poll-interval is not supported by this remote")
|
return errors.New("poll-interval is not supported by this remote")
|
||||||
|
|
|
@ -40,7 +40,7 @@ var (
|
||||||
checkStreaming bool
|
checkStreaming bool
|
||||||
checkBase32768 bool
|
checkBase32768 bool
|
||||||
all bool
|
all bool
|
||||||
uploadWait time.Duration
|
uploadWait fs.Duration
|
||||||
positionLeftRe = regexp.MustCompile(`(?s)^(.*)-position-left-([[:xdigit:]]+)$`)
|
positionLeftRe = regexp.MustCompile(`(?s)^(.*)-position-left-([[:xdigit:]]+)$`)
|
||||||
positionMiddleRe = regexp.MustCompile(`(?s)^position-middle-([[:xdigit:]]+)-(.*)-$`)
|
positionMiddleRe = regexp.MustCompile(`(?s)^position-middle-([[:xdigit:]]+)-(.*)-$`)
|
||||||
positionRightRe = regexp.MustCompile(`(?s)^position-right-([[:xdigit:]]+)-(.*)$`)
|
positionRightRe = regexp.MustCompile(`(?s)^position-right-([[:xdigit:]]+)-(.*)$`)
|
||||||
|
@ -52,7 +52,7 @@ func init() {
|
||||||
flags.StringVarP(cmdFlags, &writeJSON, "write-json", "", "", "Write results to file", "")
|
flags.StringVarP(cmdFlags, &writeJSON, "write-json", "", "", "Write results to file", "")
|
||||||
flags.BoolVarP(cmdFlags, &checkNormalization, "check-normalization", "", false, "Check UTF-8 Normalization", "")
|
flags.BoolVarP(cmdFlags, &checkNormalization, "check-normalization", "", false, "Check UTF-8 Normalization", "")
|
||||||
flags.BoolVarP(cmdFlags, &checkControl, "check-control", "", false, "Check control characters", "")
|
flags.BoolVarP(cmdFlags, &checkControl, "check-control", "", false, "Check control characters", "")
|
||||||
flags.DurationVarP(cmdFlags, &uploadWait, "upload-wait", "", 0, "Wait after writing a file", "")
|
flags.FVarP(cmdFlags, &uploadWait, "upload-wait", "", "Wait after writing a file", "")
|
||||||
flags.BoolVarP(cmdFlags, &checkLength, "check-length", "", false, "Check max filename length", "")
|
flags.BoolVarP(cmdFlags, &checkLength, "check-length", "", false, "Check max filename length", "")
|
||||||
flags.BoolVarP(cmdFlags, &checkStreaming, "check-streaming", "", false, "Check uploads with indeterminate file size", "")
|
flags.BoolVarP(cmdFlags, &checkStreaming, "check-streaming", "", false, "Check uploads with indeterminate file size", "")
|
||||||
flags.BoolVarP(cmdFlags, &checkBase32768, "check-base32768", "", false, "Check can store all possible base32768 characters", "")
|
flags.BoolVarP(cmdFlags, &checkBase32768, "check-base32768", "", false, "Check can store all possible base32768 characters", "")
|
||||||
|
@ -204,7 +204,7 @@ func (r *results) writeFile(path string) (fs.Object, error) {
|
||||||
src := object.NewStaticObjectInfo(path, time.Now(), int64(len(contents)), true, nil, r.f)
|
src := object.NewStaticObjectInfo(path, time.Now(), int64(len(contents)), true, nil, r.f)
|
||||||
obj, err := r.f.Put(r.ctx, bytes.NewBufferString(contents), src)
|
obj, err := r.f.Put(r.ctx, bytes.NewBufferString(contents), src)
|
||||||
if uploadWait > 0 {
|
if uploadWait > 0 {
|
||||||
time.Sleep(uploadWait)
|
time.Sleep(time.Duration(uploadWait))
|
||||||
}
|
}
|
||||||
return obj, err
|
return obj, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ func (jobs *Jobs) kickExpire() {
|
||||||
jobs.mu.Lock()
|
jobs.mu.Lock()
|
||||||
defer jobs.mu.Unlock()
|
defer jobs.mu.Unlock()
|
||||||
if !jobs.expireRunning {
|
if !jobs.expireRunning {
|
||||||
time.AfterFunc(jobs.opt.JobExpireInterval, jobs.Expire)
|
time.AfterFunc(time.Duration(jobs.opt.JobExpireInterval), jobs.Expire)
|
||||||
jobs.expireRunning = true
|
jobs.expireRunning = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,13 +159,13 @@ func (jobs *Jobs) Expire() {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
for ID, job := range jobs.jobs {
|
for ID, job := range jobs.jobs {
|
||||||
job.mu.Lock()
|
job.mu.Lock()
|
||||||
if job.Finished && now.Sub(job.EndTime) > jobs.opt.JobExpireDuration {
|
if job.Finished && now.Sub(job.EndTime) > time.Duration(jobs.opt.JobExpireDuration) {
|
||||||
delete(jobs.jobs, ID)
|
delete(jobs.jobs, ID)
|
||||||
}
|
}
|
||||||
job.mu.Unlock()
|
job.mu.Unlock()
|
||||||
}
|
}
|
||||||
if len(jobs.jobs) != 0 {
|
if len(jobs.jobs) != 0 {
|
||||||
time.AfterFunc(jobs.opt.JobExpireInterval, jobs.Expire)
|
time.AfterFunc(time.Duration(jobs.opt.JobExpireInterval), jobs.Expire)
|
||||||
jobs.expireRunning = true
|
jobs.expireRunning = true
|
||||||
} else {
|
} else {
|
||||||
jobs.expireRunning = false
|
jobs.expireRunning = false
|
||||||
|
|
|
@ -24,7 +24,7 @@ func TestNewJobs(t *testing.T) {
|
||||||
func TestJobsKickExpire(t *testing.T) {
|
func TestJobsKickExpire(t *testing.T) {
|
||||||
testy.SkipUnreliable(t)
|
testy.SkipUnreliable(t)
|
||||||
jobs := newJobs()
|
jobs := newJobs()
|
||||||
jobs.opt.JobExpireInterval = time.Millisecond
|
jobs.opt.JobExpireInterval = fs.Duration(time.Millisecond)
|
||||||
assert.Equal(t, false, jobs.expireRunning)
|
assert.Equal(t, false, jobs.expireRunning)
|
||||||
jobs.kickExpire()
|
jobs.kickExpire()
|
||||||
jobs.mu.Lock()
|
jobs.mu.Lock()
|
||||||
|
@ -41,7 +41,7 @@ func TestJobsExpire(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
wait := make(chan struct{})
|
wait := make(chan struct{})
|
||||||
jobs := newJobs()
|
jobs := newJobs()
|
||||||
jobs.opt.JobExpireInterval = time.Millisecond
|
jobs.opt.JobExpireInterval = fs.Duration(time.Millisecond)
|
||||||
assert.Equal(t, false, jobs.expireRunning)
|
assert.Equal(t, false, jobs.expireRunning)
|
||||||
var gotJobID int64
|
var gotJobID int64
|
||||||
var gotJob *Job
|
var gotJob *Job
|
||||||
|
@ -64,7 +64,7 @@ func TestJobsExpire(t *testing.T) {
|
||||||
assert.Equal(t, 1, len(jobs.jobs))
|
assert.Equal(t, 1, len(jobs.jobs))
|
||||||
jobs.mu.Lock()
|
jobs.mu.Lock()
|
||||||
job.mu.Lock()
|
job.mu.Lock()
|
||||||
job.EndTime = time.Now().Add(-rc.Opt.JobExpireDuration - 60*time.Second)
|
job.EndTime = time.Now().Add(-time.Duration(rc.Opt.JobExpireDuration) - 60*time.Second)
|
||||||
assert.Equal(t, true, jobs.expireRunning)
|
assert.Equal(t, true, jobs.expireRunning)
|
||||||
job.mu.Unlock()
|
job.mu.Unlock()
|
||||||
jobs.mu.Unlock()
|
jobs.mu.Unlock()
|
||||||
|
|
|
@ -75,12 +75,12 @@ var OptionsInfo = fs.Options{{
|
||||||
Groups: "RC,Metrics",
|
Groups: "RC,Metrics",
|
||||||
}, {
|
}, {
|
||||||
Name: "rc_job_expire_duration",
|
Name: "rc_job_expire_duration",
|
||||||
Default: 60 * time.Second,
|
Default: fs.Duration(60 * time.Second),
|
||||||
Help: "Expire finished async jobs older than this value",
|
Help: "Expire finished async jobs older than this value",
|
||||||
Groups: "RC",
|
Groups: "RC",
|
||||||
}, {
|
}, {
|
||||||
Name: "rc_job_expire_interval",
|
Name: "rc_job_expire_interval",
|
||||||
Default: 10 * time.Second,
|
Default: fs.Duration(10 * time.Second),
|
||||||
Help: "Interval to check for expired async jobs",
|
Help: "Interval to check for expired async jobs",
|
||||||
Groups: "RC",
|
Groups: "RC",
|
||||||
}, {
|
}, {
|
||||||
|
@ -120,8 +120,8 @@ type Options struct {
|
||||||
MetricsHTTP libhttp.Config `config:"metrics"`
|
MetricsHTTP libhttp.Config `config:"metrics"`
|
||||||
MetricsAuth libhttp.AuthConfig `config:"metrics"`
|
MetricsAuth libhttp.AuthConfig `config:"metrics"`
|
||||||
MetricsTemplate libhttp.TemplateConfig `config:"metrics"`
|
MetricsTemplate libhttp.TemplateConfig `config:"metrics"`
|
||||||
JobExpireDuration time.Duration `config:"rc_job_expire_duration"`
|
JobExpireDuration fs.Duration `config:"rc_job_expire_duration"`
|
||||||
JobExpireInterval time.Duration `config:"rc_job_expire_interval"`
|
JobExpireInterval fs.Duration `config:"rc_job_expire_interval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opt is the default values used for Options
|
// Opt is the default values used for Options
|
||||||
|
|
|
@ -120,11 +120,11 @@ var ConfigInfo = fs.Options{{
|
||||||
Help: "IPaddress:Port or :Port to bind server to",
|
Help: "IPaddress:Port or :Port to bind server to",
|
||||||
}, {
|
}, {
|
||||||
Name: "server_read_timeout",
|
Name: "server_read_timeout",
|
||||||
Default: 1 * time.Hour,
|
Default: fs.Duration(1 * time.Hour),
|
||||||
Help: "Timeout for server reading data",
|
Help: "Timeout for server reading data",
|
||||||
}, {
|
}, {
|
||||||
Name: "server_write_timeout",
|
Name: "server_write_timeout",
|
||||||
Default: 1 * time.Hour,
|
Default: fs.Duration(1 * time.Hour),
|
||||||
Help: "Timeout for server writing data",
|
Help: "Timeout for server writing data",
|
||||||
}, {
|
}, {
|
||||||
Name: "max_header_bytes",
|
Name: "max_header_bytes",
|
||||||
|
@ -158,25 +158,25 @@ var ConfigInfo = fs.Options{{
|
||||||
|
|
||||||
// Config contains options for the http Server
|
// Config contains options for the http Server
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ListenAddr []string `config:"addr"` // Port to listen on
|
ListenAddr []string `config:"addr"` // Port to listen on
|
||||||
BaseURL string `config:"baseurl"` // prefix to strip from URLs
|
BaseURL string `config:"baseurl"` // prefix to strip from URLs
|
||||||
ServerReadTimeout time.Duration `config:"server_read_timeout"` // Timeout for server reading data
|
ServerReadTimeout fs.Duration `config:"server_read_timeout"` // Timeout for server reading data
|
||||||
ServerWriteTimeout time.Duration `config:"server_write_timeout"` // Timeout for server writing data
|
ServerWriteTimeout fs.Duration `config:"server_write_timeout"` // Timeout for server writing data
|
||||||
MaxHeaderBytes int `config:"max_header_bytes"` // Maximum size of request header
|
MaxHeaderBytes int `config:"max_header_bytes"` // Maximum size of request header
|
||||||
TLSCert string `config:"cert"` // Path to TLS PEM public key certificate file (can also include intermediate/CA certificates)
|
TLSCert string `config:"cert"` // Path to TLS PEM public key certificate file (can also include intermediate/CA certificates)
|
||||||
TLSKey string `config:"key"` // Path to TLS PEM private key file
|
TLSKey string `config:"key"` // Path to TLS PEM private key file
|
||||||
TLSCertBody []byte `config:"-"` // TLS PEM public key certificate body (can also include intermediate/CA certificates), ignores TLSCert
|
TLSCertBody []byte `config:"-"` // TLS PEM public key certificate body (can also include intermediate/CA certificates), ignores TLSCert
|
||||||
TLSKeyBody []byte `config:"-"` // TLS PEM private key body, ignores TLSKey
|
TLSKeyBody []byte `config:"-"` // TLS PEM private key body, ignores TLSKey
|
||||||
ClientCA string `config:"client_ca"` // Path to TLS PEM CA file with certificate authorities to verify clients with
|
ClientCA string `config:"client_ca"` // Path to TLS PEM CA file with certificate authorities to verify clients with
|
||||||
MinTLSVersion string `config:"min_tls_version"` // MinTLSVersion contains the minimum TLS version that is acceptable.
|
MinTLSVersion string `config:"min_tls_version"` // MinTLSVersion contains the minimum TLS version that is acceptable.
|
||||||
AllowOrigin string `config:"allow_origin"` // AllowOrigin sets the Access-Control-Allow-Origin header
|
AllowOrigin string `config:"allow_origin"` // AllowOrigin sets the Access-Control-Allow-Origin header
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddFlagsPrefix adds flags for the httplib
|
// AddFlagsPrefix adds flags for the httplib
|
||||||
func (cfg *Config) AddFlagsPrefix(flagSet *pflag.FlagSet, prefix string) {
|
func (cfg *Config) AddFlagsPrefix(flagSet *pflag.FlagSet, prefix string) {
|
||||||
flags.StringArrayVarP(flagSet, &cfg.ListenAddr, prefix+"addr", "", cfg.ListenAddr, "IPaddress:Port, :Port or [unix://]/path/to/socket to bind server to", prefix)
|
flags.StringArrayVarP(flagSet, &cfg.ListenAddr, prefix+"addr", "", cfg.ListenAddr, "IPaddress:Port, :Port or [unix://]/path/to/socket to bind server to", prefix)
|
||||||
flags.DurationVarP(flagSet, &cfg.ServerReadTimeout, prefix+"server-read-timeout", "", cfg.ServerReadTimeout, "Timeout for server reading data", prefix)
|
flags.FVarP(flagSet, &cfg.ServerReadTimeout, prefix+"server-read-timeout", "", "Timeout for server reading data", prefix)
|
||||||
flags.DurationVarP(flagSet, &cfg.ServerWriteTimeout, prefix+"server-write-timeout", "", cfg.ServerWriteTimeout, "Timeout for server writing data", prefix)
|
flags.FVarP(flagSet, &cfg.ServerWriteTimeout, prefix+"server-write-timeout", "", "Timeout for server writing data", prefix)
|
||||||
flags.IntVarP(flagSet, &cfg.MaxHeaderBytes, prefix+"max-header-bytes", "", cfg.MaxHeaderBytes, "Maximum size of request header", prefix)
|
flags.IntVarP(flagSet, &cfg.MaxHeaderBytes, prefix+"max-header-bytes", "", cfg.MaxHeaderBytes, "Maximum size of request header", prefix)
|
||||||
flags.StringVarP(flagSet, &cfg.TLSCert, prefix+"cert", "", cfg.TLSCert, "Path to TLS PEM public key certificate file (can also include intermediate/CA certificates)", prefix)
|
flags.StringVarP(flagSet, &cfg.TLSCert, prefix+"cert", "", cfg.TLSCert, "Path to TLS PEM public key certificate file (can also include intermediate/CA certificates)", prefix)
|
||||||
flags.StringVarP(flagSet, &cfg.TLSKey, prefix+"key", "", cfg.TLSKey, "Path to TLS PEM private key file", prefix)
|
flags.StringVarP(flagSet, &cfg.TLSKey, prefix+"key", "", cfg.TLSKey, "Path to TLS PEM private key file", prefix)
|
||||||
|
@ -198,8 +198,8 @@ func AddHTTPFlagsPrefix(flagSet *pflag.FlagSet, prefix string, cfg *Config) {
|
||||||
func DefaultCfg() Config {
|
func DefaultCfg() Config {
|
||||||
return Config{
|
return Config{
|
||||||
ListenAddr: []string{"127.0.0.1:8080"},
|
ListenAddr: []string{"127.0.0.1:8080"},
|
||||||
ServerReadTimeout: 1 * time.Hour,
|
ServerReadTimeout: fs.Duration(1 * time.Hour),
|
||||||
ServerWriteTimeout: 1 * time.Hour,
|
ServerWriteTimeout: fs.Duration(1 * time.Hour),
|
||||||
MaxHeaderBytes: 4096,
|
MaxHeaderBytes: 4096,
|
||||||
MinTLSVersion: "tls1.0",
|
MinTLSVersion: "tls1.0",
|
||||||
}
|
}
|
||||||
|
@ -272,8 +272,8 @@ func newInstance(ctx context.Context, s *Server, listener net.Listener, tlsCfg *
|
||||||
listener: listener,
|
listener: listener,
|
||||||
httpServer: &http.Server{
|
httpServer: &http.Server{
|
||||||
Handler: s.mux,
|
Handler: s.mux,
|
||||||
ReadTimeout: s.cfg.ServerReadTimeout,
|
ReadTimeout: time.Duration(s.cfg.ServerReadTimeout),
|
||||||
WriteTimeout: s.cfg.ServerWriteTimeout,
|
WriteTimeout: time.Duration(s.cfg.ServerWriteTimeout),
|
||||||
MaxHeaderBytes: s.cfg.MaxHeaderBytes,
|
MaxHeaderBytes: s.cfg.MaxHeaderBytes,
|
||||||
ReadHeaderTimeout: 10 * time.Second, // time to send the headers
|
ReadHeaderTimeout: 10 * time.Second, // time to send the headers
|
||||||
IdleTimeout: 60 * time.Second, // time to keep idle connections open
|
IdleTimeout: 60 * time.Second, // time to keep idle connections open
|
||||||
|
|
Loading…
Reference in New Issue