Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
apaas-meshproxy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gzga-jzapi
apaas-meshproxy
Commits
dac29bf5
Commit
dac29bf5
authored
Jul 18, 2020
by
张宇迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CI SKIP]
parent
2900fd96
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
3 deletions
+62
-3
src/handler/proxyhandler.go
src/handler/proxyhandler.go
+39
-0
src/main.go
src/main.go
+1
-1
src/model/tables/service.go
src/model/tables/service.go
+8
-0
src/router/router.go
src/router/router.go
+2
-2
src/service/field.go
src/service/field.go
+12
-0
No files found.
src/handler/proxyhandler.go
View file @
dac29bf5
...
...
@@ -11,6 +11,7 @@ import (
"github.com/vulcand/oxy/testutils"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/service"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools"
"io/ioutil"
"net/http"
"strconv"
...
...
@@ -174,3 +175,41 @@ func getHost(url string) (path string) {
}
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
}
src/main.go
View file @
dac29bf5
...
...
@@ -18,7 +18,7 @@ import (
var
(
argPort
=
pflag
.
Int
(
"port"
,
8011
,
""
)
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"
,
""
)
redisTag
=
pflag
.
String
(
"redisTag"
,
"apaas-mesh-proxy"
,
""
)
confPath
=
pflag
.
String
(
"confPath"
,
"/app/config/proxy.json"
,
""
)
...
...
src/model/tables/service.go
0 → 100644
View file @
dac29bf5
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"`
}
src/router/router.go
View file @
dac29bf5
...
...
@@ -32,8 +32,8 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
e
.
Use
(
middleware
...
)
root
:=
e
.
Group
(
fmt
.
Sprintf
(
"%s/%s"
,
config
.
Prefix
,
config
.
MeshId
))
{
root
.
Any
(
"/:applyId"
,
handler
.
Proxy
)
root
.
GET
(
"/:applyId/health
"
,
handler
.
Proxy
)
root
.
GET
(
"/health"
,
handler
.
HealthCheck
)
root
.
Any
(
"/service/:applyId
"
,
handler
.
Proxy
)
}
return
e
}
src/service/field.go
View file @
dac29bf5
...
...
@@ -16,6 +16,7 @@ import (
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/dao"
"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/tables"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools/dataconvertutil"
"strconv"
...
...
@@ -444,3 +445,14 @@ func GetRealPath(applyId string) (res model.ProxyData, err error) {
}
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment