2021-04-22 14:56:25 +00:00
|
|
|
package routes
|
2021-04-03 06:11:12 +00:00
|
|
|
|
2021-04-22 14:56:25 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
2021-03-01 19:01:45 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2021-04-22 14:56:25 +00:00
|
|
|
)
|
2021-04-03 06:11:12 +00:00
|
|
|
|
|
|
|
// Prm groups the required parameters of the Builder's constructor.
|
|
|
|
//
|
|
|
|
// All values must comply with the requirements imposed on them.
|
|
|
|
// Passing incorrect parameter values will result in constructor
|
|
|
|
// failure (error or panic depending on the implementation).
|
|
|
|
type Prm struct {
|
|
|
|
// Manager builder for current node.
|
|
|
|
//
|
|
|
|
// Must not be nil.
|
2021-04-22 14:56:25 +00:00
|
|
|
ManagerBuilder common.ManagerBuilder
|
2021-03-01 19:01:45 +00:00
|
|
|
|
|
|
|
Log *logger.Logger
|
2021-04-03 06:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Builder represents component that routes node to its managers.
|
|
|
|
//
|
|
|
|
// For correct operation, Builder must be created using
|
|
|
|
// the constructor (New) based on the required parameters
|
|
|
|
// and optional components. After successful creation,
|
|
|
|
// the Builder is immediately ready to work through API.
|
|
|
|
type Builder struct {
|
2021-04-22 14:56:25 +00:00
|
|
|
managerBuilder common.ManagerBuilder
|
2021-03-01 19:01:45 +00:00
|
|
|
log *logger.Logger
|
2021-04-03 06:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const invalidPrmValFmt = "invalid parameter %s (%T):%v"
|
|
|
|
|
|
|
|
func panicOnPrmValue(n string, v interface{}) {
|
|
|
|
panic(fmt.Sprintf(invalidPrmValFmt, n, v, v))
|
|
|
|
}
|
|
|
|
|
|
|
|
// New creates a new instance of the Builder.
|
|
|
|
//
|
|
|
|
// Panics if at least one value of the parameters is invalid.
|
|
|
|
//
|
|
|
|
// The created Builder does not require additional
|
|
|
|
// initialization and is completely ready for work.
|
|
|
|
func New(prm Prm) *Builder {
|
|
|
|
switch {
|
|
|
|
case prm.ManagerBuilder == nil:
|
|
|
|
panicOnPrmValue("ManagerBuilder", prm.ManagerBuilder)
|
2021-03-01 19:01:45 +00:00
|
|
|
case prm.Log == nil:
|
|
|
|
panicOnPrmValue("Logger", prm.Log)
|
2021-04-03 06:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &Builder{
|
|
|
|
managerBuilder: prm.ManagerBuilder,
|
2021-03-01 19:01:45 +00:00
|
|
|
log: prm.Log,
|
2021-04-03 06:11:12 +00:00
|
|
|
}
|
|
|
|
}
|