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
ff11388b
Commit
ff11388b
authored
Oct 24, 2019
by
gaoshiyao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新路由设置
parent
64dde16d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
23 deletions
+25
-23
readme.md
readme.md
+8
-1
src/handler/counthandler.go
src/handler/counthandler.go
+7
-15
src/handler/proxyhandler.go
src/handler/proxyhandler.go
+7
-2
src/main.go
src/main.go
+0
-4
src/router/router.go
src/router/router.go
+3
-1
No files found.
readme.md
View file @
ff11388b
...
...
@@ -13,4 +13,11 @@ PROXY_PATH=/cigservice/baseservice/fillder/turnover?applyId=0419f3e1-8e16-4e5e-a
# 前端界面
# 注: 前端项目不可有前缀路由
PROXY_HOST=apaas.wodcloud.com
PROXY_PATH=/vuemap
\ No newline at end of file
PROXY_PATH=/vuemap
# 查询调用次数
/${prefix}/count
# 代理
/${prefix}/count
\ No newline at end of file
src/handler/counthandler.go
View file @
ff11388b
...
...
@@ -2,27 +2,19 @@ package handler
import
(
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/client"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/config"
)
// CountHandler , a proxy handler
type
CountHandler
struct
{
}
// CreateCountHandler , a proxy handler
func
CreateCountHandler
()
(
*
CountHandler
,
error
)
{
handler
:=
new
(
CountHandler
)
return
handler
,
nil
}
func
(
handler
*
CountHandler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
GetCount
(
c
*
gin
.
Context
)
{
redis
,
err
:=
client
.
GetRedisClient
()
if
err
!=
nil
{
w
.
Write
([]
byte
(
err
.
Error
())
)
c
.
Error
(
err
)
}
ic
,
err
:=
redis
.
Get
(
fmt
.
Sprintf
(
"%s%s"
,
config
.
ProxyHost
,
config
.
ProxyPath
))
w
.
Write
([]
byte
(
ic
))
c
.
JSON
(
200
,
gin
.
H
{
"Key"
:
fmt
.
Sprintf
(
"%s%s"
,
config
.
ProxyHost
,
config
.
ProxyPath
),
"Count"
:
ic
,
})
}
src/handler/proxyhandler.go
View file @
ff11388b
...
...
@@ -3,6 +3,7 @@ package handler
import
(
"fmt"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"net/http"
"strings"
...
...
@@ -26,16 +27,20 @@ func Proxy(c *gin.Context) {
return
}
req
:=
c
.
Request
baseUrl
:=
"http://"
+
req
.
Host
+
req
.
URL
.
Path
req
.
URL
=
testutils
.
ParseURI
(
getProxyURL
(
req
))
req
.
RequestURI
=
getRequestURI
(
req
)
req
.
Host
=
req
.
URL
.
Host
fmt
.
Println
(
req
.
URL
,
req
.
RequestURI
,
req
.
Host
)
logrus
.
Info
(
"************************************"
)
logrus
.
Info
(
"* 调用地址:"
,
baseUrl
)
logrus
.
Info
(
"* 转发地址:"
,
req
.
URL
)
logrus
.
Info
(
"************************************"
)
fwd
.
ServeHTTP
(
c
.
Writer
,
req
)
}
func
getProxyURL
(
req
*
http
.
Request
)
string
{
path
:=
req
.
URL
.
Path
path
=
strings
.
Replace
(
req
.
URL
.
Path
,
config
.
Prefix
,
config
.
ProxyPath
,
1
)
path
=
strings
.
Replace
(
req
.
URL
.
Path
,
config
.
Prefix
+
"/proxy"
,
config
.
ProxyPath
,
1
)
rawQuery
:=
req
.
URL
.
RawQuery
var
result
=
""
if
rawQuery
==
""
{
...
...
src/main.go
View file @
ff11388b
...
...
@@ -25,10 +25,6 @@ func main() {
pflag
.
Parse
()
initEnv
()
initConfig
()
//proxyhandler, _ := handler.CreateProxyHandler()
//counthandler, _ := handler.CreateCountHandler()
//http.Handle(fmt.Sprintf("%s%s", *argPrefix, "/count"), counthandler)
//http.Handle(*argPrefix, proxyhandler)
server
()
}
...
...
src/router/router.go
View file @
ff11388b
...
...
@@ -31,7 +31,9 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
e
.
Use
(
middleware
...
)
root
:=
e
.
Group
(
config
.
Prefix
)
{
root
.
Any
(
"*action"
,
handler
.
Proxy
)
root
.
GET
(
"/count"
,
handler
.
GetCount
)
root
.
Any
(
"/proxy/*action"
,
handler
.
Proxy
)
}
return
e
}
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