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


Golang ProtocolClient.WriteJson方法代碼示例

本文整理匯總了Golang中github.com/nyxtom/broadcast/server.ProtocolClient.WriteJson方法的典型用法代碼示例。如果您正苦於以下問題:Golang ProtocolClient.WriteJson方法的具體用法?Golang ProtocolClient.WriteJson怎麽用?Golang ProtocolClient.WriteJson使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/nyxtom/broadcast/server.ProtocolClient的用法示例。


在下文中一共展示了ProtocolClient.WriteJson方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: FindEdges

func (b *BGraphBackend) FindEdges(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 1 {
		client.WriteError(errors.New("*e takes at least 1 parameter (*e vertex [vertex ...])"))
		client.Flush()
		return nil
	}

	vertexEdges := make(map[string]map[string]float64)
	for _, k := range d {
		key := string(k)
		edges := b.db.findEdges(key)
		if edges != nil {
			vertexEdges[key] = edges
		}
	}

	if len(vertexEdges) > 0 {
		client.WriteJson(vertexEdges)
		client.Flush()
	} else {
		client.WriteNull()
		client.Flush()
	}
	return nil
}
開發者ID:nyxtom,項目名稱:broadcast-graph,代碼行數:26,代碼來源:bgraph_backend.go

示例2: Counters

func (stats *StatsBackend) Counters(data interface{}, client server.ProtocolClient) error {
	results, err := stats.mem.Counters()
	if err != nil {
		client.WriteError(err)
		client.Flush()
		return nil
	}

	client.WriteJson(results)
	client.Flush()
	return nil
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:12,代碼來源:metrics.go

示例3: EditFile

func (t *TermBackend) EditFile(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) > 0 {
		fileName := string(d[0])
		content, err := ioutil.ReadFile(path.Join(t.homeDir, fileName))
		if err == nil {
			fileMap := make(map[string]string)
			fileMap["filename"] = fileName
			fileMap["contents"] = string(content)
			client.WriteJson(fileMap)
			client.Flush()
		} else {
			fileMap := make(map[string]string)
			fileMap["filename"] = fileName
			fileMap["contents"] = ""
			client.WriteJson(fileMap)
			client.Flush()
		}
	}

	return nil
}
開發者ID:supertigim,項目名稱:webterm,代碼行數:22,代碼來源:term_backend.go

示例4: IntersectEdges

func (b *BGraphBackend) IntersectEdges(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 2 {
		client.WriteError(errors.New("&e takes at least 2 parameters (&e vertex [vertex ...])"))
		client.Flush()
		return nil
	}

	keys := make([]string, len(d))
	for i, k := range d {
		keys[i] = string(k)
	}

	results := b.db.sumIntersectEdges(keys)
	if results != nil && len(results) > 0 {
		client.WriteJson(results)
		client.Flush()
	} else {
		client.WriteNull()
		client.Flush()
	}

	return nil
}
開發者ID:nyxtom,項目名稱:broadcast-graph,代碼行數:24,代碼來源:bgraph_backend.go

示例5: help

func (b *DefaultBackend) help(data interface{}, client server.ProtocolClient) error {
	help, _ := b.app.Help()
	client.WriteJson(help)
	client.Flush()
	return nil
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:6,代碼來源:backend.go

示例6: info

func (b *DefaultBackend) info(data interface{}, client server.ProtocolClient) error {
	status, _ := b.app.Status()
	client.WriteJson(status)
	client.Flush()
	return nil
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:6,代碼來源:backend.go


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