代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package msgprocessor
import (
"errors"
ab "github.com/hyperledger/fabric-protos-go/common"
)
// ErrEmptyMessage is returned by the empty message filter on rejection.
var ErrEmptyMessage = errors.New("Message was empty")
// Rule defines a filter function which accepts, rejects, or forwards (to the next rule) an Envelope
type Rule interface {
// Apply applies the rule to the given Envelope, either successfully or returns error
Apply(message *ab.Envelope) error
}
// EmptyRejectRule rejects empty messages
var EmptyRejectRule = Rule(emptyRejectRule{})
type emptyRejectRule struct{}
func (a emptyRejectRule) Apply(message *ab.Envelope) error {
if message.Payload == nil {
return ErrEmptyMessage
}
return nil
}
// AcceptRule always returns Accept as a result for Apply
var AcceptRule = Rule(acceptRule{})
type acceptRule struct{}
func (a acceptRule) Apply(message *ab.Envelope) error {
return nil
}
// RuleSet is used to apply a collection of rules
type RuleSet struct {
rules []Rule
}
// NewRuleSet creates a new RuleSet with the given ordered list of Rules
func NewRuleSet(rules []Rule) *RuleSet {
return &RuleSet{
rules: rules,
}
}
// Apply applies the rules given for this set in order, returning nil on valid or err on invalid
func (rs *RuleSet) Apply(message *ab.Envelope) error {
for _, rule := range rs.rules {
err := rule.Apply(message)
if err != nil {
return err
}
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。