config: add sanity check to prevent non-negative worker counts

This commit is contained in:
Conner Fromknecht committed 2019-03-13 20:32:52 -07:00
1 parent 76116f0d1a
commit d81ce61033
3 files changed
+129

No files matched your search

+21
View File
@@ -1,5 +1,7 @@
package lncfg
import "fmt"
const (
// DefaultReadWorkers is the default maximum number of concurrent
// workers used by the daemon's read pool.
@@ -26,3 +28,22 @@ type Workers struct {
// Sig is the maximum number of concurrent sig pool workers.
Sig int `long:"sig" description:"Maximum number of concurrent sig pool workers."`
}
// Validate checks the Workers configuration to ensure that the input values are
// sane.
func (w *Workers) Validate() error {
if w.Read <= 0 {
return fmt.Errorf("number of read workers (%d) must be "+
"positive", w.Read)
}
if w.Write <= 0 {
return fmt.Errorf("number of write workers (%d) must be "+
"positive", w.Write)
}
if w.Sig <= 0 {
return fmt.Errorf("number of sig workers (%d) must be "+
"positive", w.Sig)
}
return nil
}