github.com/15mga/kiwi@v0.0.2-0.20240324021231-b95d5c3ac751/node_meta.go (about)

     1  package kiwi
     2  
     3  import (
     4  	"github.com/15mga/kiwi/sid"
     5  	"github.com/15mga/kiwi/util"
     6  	"time"
     7  )
     8  
     9  var (
    10  	_NodeMeta = &NodeMeta{
    11  		StartTime: time.Now().Unix(),
    12  		Data:      util.M{},
    13  		Services:  make(map[TSvc]string, 8),
    14  	}
    15  )
    16  
    17  func GetNodeMeta() *NodeMeta {
    18  	return _NodeMeta
    19  }
    20  
    21  type NodeMeta struct {
    22  	Ip        string
    23  	Port      int
    24  	NodeId    int64
    25  	StartTime int64
    26  	Data      util.M
    27  	Mode      string
    28  	Services  map[TSvc]string
    29  }
    30  
    31  func (n *NodeMeta) Init(id int64) {
    32  	sid.SetNodeId(id)
    33  	n.NodeId = sid.GetId()
    34  	SetLogDefParams(util.M{
    35  		"node": n.NodeId,
    36  	})
    37  }
    38  
    39  func (n *NodeMeta) AddService(svc TSvc, ver string) {
    40  	n.Services[svc] = ver
    41  }
    42  
    43  func (n *NodeMeta) HasService(svc TSvc) bool {
    44  	_, ok := n.Services[svc]
    45  	return ok
    46  }