forked from TrueCloudLab/frostfs-node
[#625] morph/client: make method names constant
We don't use custom names and the only place where custom method option is used it provides the default name and can be omitted. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
35dec2f494
commit
3c5b62d839
44 changed files with 249 additions and 1097 deletions
|
@ -14,133 +14,18 @@ import (
|
|||
// and can lead to panic.
|
||||
type Client struct {
|
||||
client *client.StaticClient // static Audit contract client
|
||||
|
||||
*cfg // contract method names
|
||||
}
|
||||
|
||||
// Option is a client configuration change function.
|
||||
type Option func(*cfg)
|
||||
|
||||
type cfg struct {
|
||||
putResultMethod, // put audit result method name for invocation
|
||||
getResultMethod, // get audit result method name for invocation
|
||||
listResultsMethod string // list all audit result IDs method name for invocation
|
||||
listByEpochResultsMethod string // list audit result IDs by epoch method name for invocation
|
||||
listByCIDResultsMethod string // list audit result IDs by epoch and CID method name for invocation
|
||||
listByNodeResultsMethod string // list audit result IDs by epoch, CID, and node key method name for invocation
|
||||
}
|
||||
|
||||
const (
|
||||
defaultPutResultMethod = "put" // default "put audit result" method name
|
||||
defaultGetResultMethod = "get" // default "get audit result" method name
|
||||
defaultListResultsMethod = "list" // default "list all audit result IDs" method name
|
||||
defaultListByEpochResultsMethod = "listByEpoch" // default "list audit result IDs by epoch" method name
|
||||
defaultListByCIDResultsMethod = "listByCID" // default "list audit result IDs by epoch and CID" method name
|
||||
defaultListByNodeResultsMethod = "listByNode" // default "list audit result IDs by epoch, CID and node key" method name
|
||||
putResultMethod = "put"
|
||||
getResultMethod = "get"
|
||||
listResultsMethod = "list"
|
||||
listByEpochResultsMethod = "listByEpoch"
|
||||
listByCIDResultsMethod = "listByCID"
|
||||
listByNodeResultsMethod = "listByNode"
|
||||
)
|
||||
|
||||
func defaultConfig() *cfg {
|
||||
return &cfg{
|
||||
putResultMethod: defaultPutResultMethod,
|
||||
getResultMethod: defaultGetResultMethod,
|
||||
listResultsMethod: defaultListResultsMethod,
|
||||
listByEpochResultsMethod: defaultListByEpochResultsMethod,
|
||||
listByCIDResultsMethod: defaultListByCIDResultsMethod,
|
||||
listByNodeResultsMethod: defaultListByNodeResultsMethod,
|
||||
}
|
||||
}
|
||||
|
||||
// New creates, initializes and returns the Client instance.
|
||||
//
|
||||
// Other values are set according to provided options, or by default:
|
||||
// * "put audit result" method name: put;
|
||||
// * "list audit results" method name: list.
|
||||
//
|
||||
// If desired option satisfies the default value, it can be omitted.
|
||||
// If multiple options of the same config value are supplied,
|
||||
// the option with the highest index in the arguments will be used.
|
||||
func New(c *client.StaticClient, opts ...Option) *Client {
|
||||
res := &Client{
|
||||
client: c,
|
||||
cfg: defaultConfig(), // build default configuration
|
||||
}
|
||||
|
||||
// apply options
|
||||
for _, opt := range opts {
|
||||
opt(res.cfg)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// WithPutAuditResultMethod returns a client constructor option that
|
||||
// specifies the "put audit result" method name.
|
||||
//
|
||||
// Ignores empty value.
|
||||
func WithPutAuditResultMethod(n string) Option {
|
||||
return func(c *cfg) {
|
||||
if n != "" {
|
||||
c.putResultMethod = n
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithGetAuditResultMethod returns a client constructor option that
|
||||
// specifies the "get audit result" method name.
|
||||
//
|
||||
// Ignores empty value.
|
||||
func WithGetAuditResultMethod(n string) Option {
|
||||
return func(c *cfg) {
|
||||
if n != "" {
|
||||
c.getResultMethod = n
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithListResultsMethod returns a client constructor option that
|
||||
// specifies the "list all audit result IDs" method name.
|
||||
//
|
||||
// Ignores empty value.
|
||||
func WithListResultsMethod(n string) Option {
|
||||
return func(c *cfg) {
|
||||
if n != "" {
|
||||
c.listResultsMethod = n
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithListByEpochResultsMethod returns a client constructor option that
|
||||
// specifies the "list audit result IDs by epoch" method name.
|
||||
//
|
||||
// Ignores empty value.
|
||||
func WithListByEpochResultsMethod(n string) Option {
|
||||
return func(c *cfg) {
|
||||
if n != "" {
|
||||
c.listByEpochResultsMethod = n
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithListByCIDResultsMethod returns a client constructor option that
|
||||
// specifies the "list audit result IDs by epoch and CID" method name.
|
||||
//
|
||||
// Ignores empty value.
|
||||
func WithListByCIDResultsMethod(n string) Option {
|
||||
return func(c *cfg) {
|
||||
if n != "" {
|
||||
c.listByCIDResultsMethod = n
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithListByNodeResultsMethod returns a client constructor option that
|
||||
// specifies the "list audit result IDs by epoch, CID, and node key" method name.
|
||||
//
|
||||
// Ignores empty value.
|
||||
func WithListByNodeResultsMethod(n string) Option {
|
||||
return func(c *cfg) {
|
||||
if n != "" {
|
||||
c.listByNodeResultsMethod = n
|
||||
}
|
||||
}
|
||||
func New(c *client.StaticClient) *Client {
|
||||
return &Client{client: c}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue