本文整理汇总了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)
}
}
示例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})
}
示例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)})
}
示例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)
}
}
示例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:
}
}
}
示例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)
}
}
示例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()),
})
}
示例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())
}
}