当前位置: 首页>>代码示例>>Golang>>正文


Golang xfer.Reporter类代码示例

本文整理汇总了Golang中github.com/weaveworks/scope/xfer.Reporter的典型用法代码示例。如果您正苦于以下问题:Golang Reporter类的具体用法?Golang Reporter怎么用?Golang Reporter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Reporter类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: makeTopologyList

// makeTopologyList returns a handler that yields an APITopologyList.
func makeTopologyList(rep xfer.Reporter) func(w http.ResponseWriter, r *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		var (
			rpt        = rep.Report()
			topologies = []APITopologyDesc{}
		)
		for name, def := range topologyRegistry {
			if def.parent != "" {
				continue // subtopology, don't show at top level
			}
			subTopologies := []APITopologyDesc{}
			for subName, subDef := range topologyRegistry {
				if subDef.parent == name {
					subTopologies = append(subTopologies, APITopologyDesc{
						Name:  subDef.human,
						URL:   "/api/topology/" + subName,
						Stats: stats(subDef.renderer.Render(rpt)),
					})
				}
			}
			topologies = append(topologies, APITopologyDesc{
				Name:          def.human,
				URL:           "/api/topology/" + name,
				SubTopologies: subTopologies,
				Stats:         stats(def.renderer.Render(rpt)),
			})
		}
		respondWith(w, http.StatusOK, topologies)
	}
}
开发者ID:philipz,项目名称:scope,代码行数:31,代码来源:api_topologies.go

示例2: handleEdge

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

	respondWith(w, http.StatusOK, APIEdge{Metadata: metadata})
}
开发者ID:philipz,项目名称:scope,代码行数:12,代码来源:api_topology.go

示例3: handleNode

// Individual nodes.
func handleNode(rep xfer.Reporter, t topologyView, w http.ResponseWriter, r *http.Request) {
	var (
		vars     = mux.Vars(r)
		nodeID   = vars["id"]
		rpt      = rep.Report()
		node, ok = t.renderer.Render(rep.Report())[nodeID]
	)
	if !ok {
		http.NotFound(w, r)
		return
	}
	respondWith(w, http.StatusOK, APINode{Node: render.MakeDetailedNode(rpt, node)})
}
开发者ID:philipz,项目名称:scope,代码行数:14,代码来源:api_topology.go

示例4: makeOriginHostHandler

// makeOriginHostHandler makes the /api/origin/* handler.
func makeOriginHostHandler(rep xfer.Reporter) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var (
			vars   = mux.Vars(r)
			nodeID = vars["id"]
		)
		origin, ok := getOriginHost(rep.Report().Host, nodeID)
		if !ok {
			http.NotFound(w, r)
			return
		}
		respondWith(w, http.StatusOK, origin)
	}
}
开发者ID:barravi,项目名称:scope,代码行数:15,代码来源:origin_host.go

示例5: handleWebsocket

func handleWebsocket(
	w http.ResponseWriter,
	r *http.Request,
	rep xfer.Reporter,
	t topologyView,
	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)
	)
	for {
		newTopo := t.renderer.Render(rep.Report())
		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 <-quit:
			return
		case <-tick:
		}
	}
}
开发者ID:philipz,项目名称:scope,代码行数:47,代码来源:api_topology.go

示例6: makeTopologyList

// makeTopologyList returns a handler that yields an APITopologyList.
func makeTopologyList(rep xfer.Reporter) func(w http.ResponseWriter, r *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		var (
			rpt        = rep.Report()
			topologies = []APITopologyDesc{}
		)
		for name, def := range topologyRegistry {
			// Don't show sub-topologies at the top level.
			if def.parent != "" {
				continue
			}
			decorateTopologyForRequest(r, &def)

			// Collect all sub-topologies of this one, depth=1 only.
			subTopologies := []APITopologyDesc{}
			for subName, subDef := range topologyRegistry {
				if subDef.parent == name {
					decorateTopologyForRequest(r, &subDef)
					subTopologies = append(subTopologies, APITopologyDesc{
						Name:    subDef.human,
						URL:     "/api/topology/" + subName,
						Options: makeTopologyOptions(subDef),
						Stats:   stats(subDef.renderer, rpt),
					})
				}
			}

			// Append.
			topologies = append(topologies, APITopologyDesc{
				Name:          def.human,
				URL:           "/api/topology/" + name,
				SubTopologies: subTopologies,
				Options:       makeTopologyOptions(def),
				Stats:         stats(def.renderer, rpt),
			})
		}
		respondWith(w, http.StatusOK, topologies)
	}
}
开发者ID:webwurst,项目名称:scope,代码行数:40,代码来源:api_topologies.go

示例7: handleTopology

// Full topology.
func handleTopology(rep xfer.Reporter, t topologyView, w http.ResponseWriter, r *http.Request) {
	respondWith(w, http.StatusOK, APITopology{
		Nodes: t.renderer.Render(rep.Report()),
	})
}
开发者ID:philipz,项目名称:scope,代码行数:6,代码来源:api_topology.go

示例8: makeRawReportHandler

// Raw report handler
func makeRawReportHandler(rep xfer.Reporter) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		// r.ParseForm()
		respondWith(w, http.StatusOK, rep.Report())
	}
}
开发者ID:philipz,项目名称:scope,代码行数:7,代码来源:api_report.go


注:本文中的github.com/weaveworks/scope/xfer.Reporter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。