"src/service/alert.go" did not exist on "155bed23b4dc802df65492385fc172911cc701ee"
Commit dac29bf5 authored by 张宇迪's avatar 张宇迪

[CI SKIP]

parent 2900fd96
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"github.com/vulcand/oxy/testutils" "github.com/vulcand/oxy/testutils"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/service" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/service"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strconv" "strconv"
...@@ -174,3 +175,41 @@ func getHost(url string) (path string) { ...@@ -174,3 +175,41 @@ func getHost(url string) (path string) {
} }
return return
} }
func HealthCheck(c *gin.Context) {
res := model.WebRes{}
proxyData, err := service.GetReqPath()
if err != nil {
res.Data = err.Error()
c.JSON(500, res)
return
}
var requstMethod string
//获取真实地址1GET 2POST 3 PUT 4 DELETE
if proxyData.ReqType == 1 {
requstMethod = "GET"
} else if proxyData.ReqType == 2 {
requstMethod = "POST"
} else if proxyData.ReqType == 3 {
requstMethod = "PUT"
} else if proxyData.ReqType == 4 {
requstMethod = "DELETE"
}
header := make(map[string]string, 0)
resp, err := tools.ProxySendRes(c.Request, requstMethod, proxyData.ReqUrl, "", header)
if err != nil {
res.Data = err.Error()
c.JSON(500, res)
return
}
fmt.Println(resp)
if resp.StatusCode < 400 {
res.Data = "success"
} else {
res.Data = "fail"
}
res.Success = 1
//请求真实地址根据返回状态码判断是否服务可用
c.JSON(200, res)
return
}
...@@ -18,7 +18,7 @@ import ( ...@@ -18,7 +18,7 @@ import (
var ( var (
argPort = pflag.Int("port", 8011, "") argPort = pflag.Int("port", 8011, "")
argPrefix = pflag.String("prefix", "/bgmesh/fiddler", "") argPrefix = pflag.String("prefix", "/bgmesh/fiddler", "")
meshId = pflag.String("meshId", "", "") meshId = pflag.String("meshId", "149", "")
redisUrl = pflag.String("redisUrl", "redis://apaas-redis.apaas-v3:6379", "") redisUrl = pflag.String("redisUrl", "redis://apaas-redis.apaas-v3:6379", "")
redisTag = pflag.String("redisTag", "apaas-mesh-proxy", "") redisTag = pflag.String("redisTag", "apaas-mesh-proxy", "")
confPath = pflag.String("confPath", "/app/config/proxy.json", "") confPath = pflag.String("confPath", "/app/config/proxy.json", "")
......
package tables
type Service struct {
Id int `json:"id"xorm:"pk"`
ReqUrl string `json:"req_url"`
ReqType int `json:"req_type"`
//ReqType string `json:"req_type"`
}
...@@ -32,8 +32,8 @@ func Load(middleware ...gin.HandlerFunc) http.Handler { ...@@ -32,8 +32,8 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
e.Use(middleware...) e.Use(middleware...)
root := e.Group(fmt.Sprintf("%s/%s", config.Prefix, config.MeshId)) root := e.Group(fmt.Sprintf("%s/%s", config.Prefix, config.MeshId))
{ {
root.Any("/:applyId", handler.Proxy) root.GET("/health", handler.HealthCheck)
root.GET("/:applyId/health", handler.Proxy) root.Any("/service/:applyId", handler.Proxy)
} }
return e return e
} }
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/dao" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/dao"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model/request" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model/request"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model/tables"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools/dataconvertutil" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools/dataconvertutil"
"strconv" "strconv"
...@@ -444,3 +445,14 @@ func GetRealPath(applyId string) (res model.ProxyData, err error) { ...@@ -444,3 +445,14 @@ func GetRealPath(applyId string) (res model.ProxyData, err error) {
} }
return return
} }
// 获取真实地址
func GetReqPath() (res tables.Service, err error) {
db, err := client.GetConnect()
if err != nil {
return
}
res = tables.Service{}
_, err = db.ID(config.MeshId).Get(&res)
return
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment