當前位置: 首頁>>代碼示例>>Golang>>正文


Golang serf.Query類代碼示例

本文整理匯總了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())))
}
開發者ID:previousnext,項目名稱:kube-ingress,代碼行數:16,代碼來源:ov_serf.go

示例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)
}
開發者ID:WIZARD-CXY,項目名稱:golang-devops-stuff,代碼行數:17,代碼來源:ipc_event_stream.go

示例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
}
開發者ID:paha,項目名稱:serf,代碼行數:25,代碼來源:ipc.go


注:本文中的github.com/hashicorp/serf/serf.Query類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。