1 Star 1 Fork 0

titan-kit/titan

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
node.go 988 Bytes
一键复制 编辑 原始数据 按行查看 历史
蝶衣人生 提交于 2021-05-29 14:04 +08:00 . first commit
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)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/titan-kit/titan.git
git@gitee.com:titan-kit/titan.git
titan-kit
titan
titan
v0.0.4

搜索帮助