code refactor

This commit is contained in:
Ulric Qin 2022-07-11 13:10:40 +08:00
parent 94847d9059
commit 616674b643
2 changed files with 11 additions and 4 deletions

View File

@ -86,13 +86,13 @@ func configRoute(r *gin.Engine, version string) {
r.POST("/prometheus/v1/query", stat(), queryPromql)
r.GET("/memory/alert-rule", alertRuleGet)
r.GET("/memory/alert-rule-location", alertRuleLocationGet)
r.GET("/memory/idents", identsGets)
r.GET("/memory/alert-mutes", mutesGets)
r.GET("/memory/alert-subscribes", subscribesGets)
r.GET("/memory/target", targetGet)
r.GET("/memory/user", userGet)
r.GET("/memory/user-group", userGroupGet)
r.GET("/memory/node/alert-rule", alertRuleNodeGet)
r.GET("/metrics", gin.WrapH(promhttp.Handler()))

View File

@ -1,6 +1,8 @@
package router
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/toolkits/pkg/ginx"
@ -45,8 +47,13 @@ func userGroupGet(c *gin.Context) {
c.JSON(200, gin.H{"id": id, "user_group": ug})
}
func alertRuleNodeGet(c *gin.Context) {
func alertRuleLocationGet(c *gin.Context) {
id := ginx.QueryStr(c, "id")
node, _ := naming.HashRing.GetNode(id)
node, err := naming.HashRing.GetNode(id)
if err != nil {
http.Error(c.Writer, err.Error(), http.StatusInternalServerError)
return
}
c.JSON(200, gin.H{"id": id, "node": node})
}
}