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


Golang render.Renderer類代碼示例

本文整理匯總了Golang中github.com/weaveworks/scope/render.Renderer的典型用法代碼示例。如果您正苦於以下問題:Golang Renderer類的具體用法?Golang Renderer怎麽用?Golang Renderer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: handleEdge

// Individual edges.
func handleEdge(rep Reporter, renderer render.Renderer, w http.ResponseWriter, r *http.Request) {
	var (
		vars     = mux.Vars(r)
		localID  = vars["local"]
		remoteID = vars["remote"]
		rpt      = rep.Report()
		metadata = renderer.EdgeMetadata(rpt, localID, remoteID)
	)

	respondWith(w, http.StatusOK, APIEdge{Metadata: metadata})
}
開發者ID:hrhelena,項目名稱:scope,代碼行數:12,代碼來源:api_topology.go

示例2: handleWebsocket

func handleWebsocket(
	w http.ResponseWriter,
	r *http.Request,
	rep Reporter,
	renderer render.Renderer,
	loop time.Duration,
) {
	conn, err := upgrader.Upgrade(w, r, nil)
	if err != nil {
		// log.Println("Upgrade:", err)
		return
	}
	defer conn.Close()

	quit := make(chan struct{})
	go func(c *websocket.Conn) {
		for { // just discard everything the browser sends
			if _, _, err := c.NextReader(); err != nil {
				close(quit)
				break
			}
		}
	}(conn)

	var (
		previousTopo render.RenderableNodes
		tick         = time.Tick(loop)
		wait         = make(chan struct{}, 1)
	)
	rep.WaitOn(wait)
	defer rep.UnWait(wait)

	for {
		newTopo := renderer.Render(rep.Report()).Prune()
		diff := render.TopoDiff(previousTopo, newTopo)
		previousTopo = newTopo

		if err := conn.SetWriteDeadline(time.Now().Add(websocketTimeout)); err != nil {
			return
		}
		if err := conn.WriteJSON(diff); err != nil {
			return
		}

		select {
		case <-wait:
		case <-tick:
		case <-quit:
			return
		}
	}
}
開發者ID:hrhelena,項目名稱:scope,代碼行數:52,代碼來源:api_topology.go

示例3: benchmarkStats

func benchmarkStats(b *testing.B, r render.Renderer) {
	report, err := loadReport()
	if err != nil {
		b.Fatal(err)
	}
	b.ReportAllocs()
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		// No way to tell if this was successful :(
		benchmarkStatsResult = r.Stats(report)
	}
}
開發者ID:rnd-ua,項目名稱:scope,代碼行數:13,代碼來源:benchmark_test.go

示例4: handleNode

// Individual nodes.
func handleNode(rep Reporter, renderer render.Renderer, w http.ResponseWriter, r *http.Request) {
	var (
		vars     = mux.Vars(r)
		nodeID   = vars["id"]
		rpt      = rep.Report()
		node, ok = renderer.Render(rep.Report())[nodeID]
	)
	if !ok {
		http.NotFound(w, r)
		return
	}
	respondWith(w, http.StatusOK, APINode{Node: render.MakeDetailedNode(rpt, node)})
}
開發者ID:hrhelena,項目名稱:scope,代碼行數:14,代碼來源:api_topology.go

示例5: handleNode

// Individual nodes.
func handleNode(ctx context.Context, renderer render.Renderer, _ render.Decorator, report report.Report, w http.ResponseWriter, r *http.Request) {
	var (
		vars       = mux.Vars(r)
		topologyID = vars["topology"]
		nodeID     = vars["id"]
		rendered   = renderer.Render(report, nil)
		node, ok   = rendered[nodeID]
	)
	if !ok {
		http.NotFound(w, r)
		return
	}
	respondWith(w, http.StatusOK, APINode{Node: detailed.MakeNode(topologyID, report, rendered, node)})
}
開發者ID:CNDonny,項目名稱:scope,代碼行數:15,代碼來源:api_topology.go

示例6: benchmarkRender

func benchmarkRender(b *testing.B, r render.Renderer) {
	report, err := loadReport()
	if err != nil {
		b.Fatal(err)
	}
	b.ReportAllocs()
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		benchmarkRenderResult = r.Render(report)
		if len(benchmarkRenderResult) == 0 {
			b.Errorf("Rendered topology contained no nodes")
		}
	}
}
開發者ID:rnd-ua,項目名稱:scope,代碼行數:15,代碼來源:benchmark_test.go

示例7: decorateWithStats

func decorateWithStats(rpt report.Report, renderer render.Renderer) topologyStats {
	var (
		nodes     int
		realNodes int
		edges     int
	)
	for _, n := range renderer.Render(rpt) {
		nodes++
		if !n.Pseudo {
			realNodes++
		}
		edges += len(n.Adjacency)
	}
	renderStats := renderer.Stats(rpt)
	return topologyStats{
		NodeCount:          nodes,
		NonpseudoNodeCount: realNodes,
		EdgeCount:          edges,
		FilteredNodes:      renderStats.FilteredNodes,
	}
}
開發者ID:pauloheck,項目名稱:scope,代碼行數:21,代碼來源:api_topologies.go

示例8: handleTopology

// Full topology.
func handleTopology(rep Reporter, renderer render.Renderer, w http.ResponseWriter, r *http.Request) {
	respondWith(w, http.StatusOK, APITopology{
		Nodes: renderer.Render(rep.Report()).Prune(),
	})
}
開發者ID:hrhelena,項目名稱:scope,代碼行數:6,代碼來源:api_topology.go

示例9: handleTopology

// Full topology.
func handleTopology(ctx context.Context, renderer render.Renderer, decorator render.Decorator, report report.Report, w http.ResponseWriter, r *http.Request) {
	respondWith(w, http.StatusOK, APITopology{
		Nodes: detailed.Summaries(report, renderer.Render(report, decorator)),
	})
}
開發者ID:CNDonny,項目名稱:scope,代碼行數:6,代碼來源:api_topology.go


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