本文整理汇总了Golang中github.com/hashicorp/serf/serf.Query类的典型用法代码示例。如果您正苦于以下问题:Golang Query类的具体用法?Golang Query怎么用?Golang Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Query类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processQuery
func (d *driver) processQuery(q *serf.Query) {
logrus.Debugf("Received query name:%s, payload:%s\n", q.Name,
string(q.Payload))
var nid, ipStr string
if _, err := fmt.Sscan(string(q.Payload), &nid, &ipStr); err != nil {
fmt.Printf("Failed to scan query payload string: %v\n", err)
}
peerMac, peerIPMask, vtep, err := d.peerDbSearch(nid, net.ParseIP(ipStr))
if err != nil {
return
}
q.Respond([]byte(fmt.Sprintf("%s %s %s", peerMac.String(), net.IP(peerIPMask).String(), vtep.String())))
}
示例2: sendQuery
// sendQuery is used to send a single query event
func (es *eventStream) sendQuery(q *serf.Query) error {
id := es.client.RegisterQuery(q)
header := responseHeader{
Seq: es.seq,
Error: "",
}
rec := queryEventRecord{
Event: q.EventType().String(),
ID: id,
LTime: q.LTime,
Name: q.Name,
Payload: q.Payload,
}
return es.client.Send(&header, &rec)
}
示例3: RegisterQuery
// RegisterQuery is used to register a pending query that may
// get a response. The ID of the query is returned
func (c *IPCClient) RegisterQuery(q *serf.Query) uint64 {
// Generate a unique-per-client ID
id := c.nextQueryID()
// Ensure the query deadline is in the future
timeout := q.Deadline().Sub(time.Now())
if timeout < 0 {
return id
}
// Register the query
c.queryLock.Lock()
c.pendingQueries[id] = q
c.queryLock.Unlock()
// Setup a timer to deregister after the timeout
time.AfterFunc(timeout, func() {
c.queryLock.Lock()
delete(c.pendingQueries, id)
c.queryLock.Unlock()
})
return id
}