Skip to content

Commit

Permalink
add api for list nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
reddec committed Oct 7, 2019
1 parent 75ed8e9 commit 0903e77
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 9 additions & 1 deletion domain/monitor/http_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (ms *service) createAPI() *gin.Engine {
engine.POST("/rpc/watch", ms.apiWatchNode)
engine.POST("/rpc/forget", ms.apiForgetNode)
engine.POST("/rpc/kill", ms.apiKillNode)

engine.POST("/rpc/nodes", ms.apiListNodes)
return engine
}

Expand Down Expand Up @@ -54,3 +54,11 @@ func (ms *service) apiKillNode(gctx *gin.Context) {
ms.Stop()
gctx.AbortWithStatus(http.StatusNoContent)
}

func (ms *service) apiListNodes(gctx *gin.Context) {
var reply struct {
Nodes []*Node `json:"nodes"`
}
reply.Nodes = ms.nodes.Copy()
gctx.JSON(http.StatusOK, reply)
}
6 changes: 3 additions & 3 deletions domain/monitor/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
)

type Node struct {
Name string
Subnet string
Fetched bool
Name string `json:"name"`
Subnet string `json:"subnet"`
Fetched bool `json:"fetched"`
cancel func()
ctx context.Context
}
Expand Down

0 comments on commit 0903e77

Please sign in to comment.