代码拉取完成,页面将自动刷新
package esb
import (
"errors"
"fmt"
"strconv"
"sync/atomic"
)
var (
_messages atomic.Value // 注意: 储存的map[int]string
_nodes = map[int]struct{}{} // 登记结点.
BIZ = add(0)
)
func Register(nm map[int]string) {
_messages.Store(nm)
}
type Node int64
func NewNode(c int) Node {
if c <= 0 {
panic("business node must greater than zero")
}
return add(c)
}
func add(n int) Node {
if _, ok := _nodes[n]; ok {
panic(fmt.Sprintf("Node: %d already exist", n))
}
_nodes[n] = struct{}{}
return Node(n)
}
func (n Node) String() string {
if cm, ok := _messages.Load().(map[int]string); ok {
if msg, ok := cm[int(n)]; ok {
return msg
}
}
return "Unknown"
}
func (n Node) IsValid() error {
if _, ok := _nodes[int(n)]; ok {
return nil
} else {
return errors.New("invalid leave type")
}
}
func Str2Node(n string) Node {
if n == "" {
return -1
}
if i, err := strconv.Atoi(n); err != nil {
return -1
} else {
return Node(i)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。