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
a747a087
Commit
a747a087
authored
Nov 06, 2019
by
gaoshiyao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新路由设置
parent
ff11388b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
78 additions
and
57 deletions
+78
-57
.beagle.yml
.beagle.yml
+3
-3
build/dockerfile
build/dockerfile
+1
-0
docs/proxy.yaml
docs/proxy.yaml
+5
-0
src/config/conf.go
src/config/conf.go
+13
-7
src/handler/counthandler.go
src/handler/counthandler.go
+9
-12
src/handler/proxyhandler.go
src/handler/proxyhandler.go
+24
-24
src/main.go
src/main.go
+22
-9
src/router/router.go
src/router/router.go
+1
-2
No files found.
.beagle.yml
View file @
a747a087
...
...
@@ -32,9 +32,9 @@ pipeline:
branch
:
[
master
]
deploy
:
image
:
registry-vpc.cn-qingdao.aliyuncs.com/wod-devops/kubernetes:1.0
namespace
:
c
ig
deployment
:
apaas-meshproxy
container
:
apaas-meshproxy
namespace
:
c
loud
deployment
:
bgproxy-test
container
:
bgproxy-test
registry
:
hub.wodcloud.com
secrets
:
-
source
:
KUBERNETES_SERVER
...
...
build/dockerfile
View file @
a747a087
FROM
{{ BASEIMAGE }}
MAINTAINER
{{ AUTHOR }}
LABEL
Author={{ AUTHOR }} Name={{ PROJECT }} Version={{ VERSION }}
RUN
mkdir
/app/config
COPY
./dist/. /app
EXPOSE
80
ENTRYPOINT
["/app/proxy", "--port=80","--prefix=test"]
docs/proxy.yaml
0 → 100644
View file @
a747a087
{
"
url"
:
"
https://apaas.wodcloud.com/cigservice/baseservice/fillder/turnover?applyId=0419f3e1-8e16-4e5e-a187-1760364c04e2"
,
"
method"
:
"
GET"
,
"
params"
:
null
}
\ No newline at end of file
src/config/conf.go
View file @
a747a087
package
config
import
"os"
var
(
ProxyHost
string
=
os
.
Getenv
(
"PROXY_HOST"
)
ProxyPath
string
=
os
.
Getenv
(
"PROXY_PATH"
)
RedisURL
string
RedisTag
string
Prefix
string
RedisURL
string
RedisTag
string
)
var
ProxyConf
=
struct
{
Url
string
`json:"url"`
Method
string
`json:"method"`
Params
[]
Param
`json:"params"`
}{}
type
Param
struct
{
Name
string
`json:"name"`
Value
string
`json:"value"`
}
src/handler/counthandler.go
View file @
a747a087
package
handler
import
(
"fmt"
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/client"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/config"
)
func
GetCount
(
c
*
gin
.
Context
)
{
redis
,
err
:=
client
.
GetRedisClient
()
if
err
!=
nil
{
c
.
Error
(
err
)
}
ic
,
err
:=
redis
.
Get
(
fmt
.
Sprintf
(
"%s%s"
,
config
.
ProxyHost
,
config
.
ProxyPath
))
c
.
JSON
(
200
,
gin
.
H
{
"Key"
:
fmt
.
Sprintf
(
"%s%s"
,
config
.
ProxyHost
,
config
.
ProxyPath
),
"Count"
:
ic
,
})
//
redis, err := client.GetRedisClient()
//
if err != nil {
//
c.Error(err)
//
}
//
ic, err := redis.Get(fmt.Sprintf("%s%s", config.ProxyHost, config.ProxyPath))
//
c.JSON(200, gin.H{
//
"Key": fmt.Sprintf("%s%s", config.ProxyHost, config.ProxyPath),
//
"Count": ic,
//
})
}
src/handler/proxyhandler.go
View file @
a747a087
...
...
@@ -5,9 +5,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"net/http"
"strings"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/client"
"github.com/vulcand/oxy/forward"
"github.com/vulcand/oxy/testutils"
...
...
@@ -39,20 +36,22 @@ func Proxy(c *gin.Context) {
}
func
getProxyURL
(
req
*
http
.
Request
)
string
{
path
:=
req
.
URL
.
Path
path
=
strings
.
Replace
(
req
.
URL
.
Path
,
config
.
Prefix
+
"/proxy"
,
config
.
ProxyPath
,
1
)
rawQuery
:=
req
.
URL
.
RawQuery
var
result
=
""
if
rawQuery
==
""
{
result
=
fmt
.
Sprintf
(
"http://%s%s"
,
config
.
ProxyHost
,
path
)
}
else
{
result
=
fmt
.
Sprintf
(
"http://%s%s?%s"
,
config
.
ProxyHost
,
path
,
rawQuery
)
}
if
strings
.
Contains
(
result
,
"?"
)
{
if
strings
.
HasSuffix
(
result
,
"/"
)
{
result
=
strings
.
TrimRight
(
result
,
"/"
)
}
}
// 获取转发地址
result
:=
config
.
ProxyConf
.
Url
//path := req.URL.Path
//path = strings.Replace(req.URL.Path, config.Prefix+"/proxy", config.ProxyPath, 1)
//rawQuery := req.URL.RawQuery
//var result = ""
//if rawQuery == "" {
// result = fmt.Sprintf("http://%s%s", config.ProxyHost, path)
//} else {
// result = fmt.Sprintf("http://%s%s?%s", config.ProxyHost, path, rawQuery)
//}
//if strings.Contains(result, "?") {
// if strings.HasSuffix(result, "/") {
// result = strings.TrimRight(result, "/")
// }
//}
return
result
}
...
...
@@ -72,11 +71,12 @@ func getRequestURI(req *http.Request) string {
计数
*/
func
count
()
error
{
redis
,
err
:=
client
.
GetRedisClient
()
if
err
!=
nil
{
return
err
}
ic
,
err
:=
redis
.
Incr
(
fmt
.
Sprintf
(
"%s%s"
,
config
.
ProxyHost
,
config
.
ProxyPath
))
_
,
err
=
ic
.
Result
()
return
err
//redis, err := client.GetRedisClient()
//if err != nil {
// return err
//}
//ic, err := redis.Incr(fmt.Sprintf("%s%s", config.ProxyHost, config.ProxyPath))
//_, err = ic.Result()
//return err
return
nil
}
src/main.go
View file @
a747a087
package
main
import
(
"encoding/json"
"fmt"
"github.com/sirupsen/logrus"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/router"
"io/ioutil"
"net/http"
"os"
"time"
"github.com/sirupsen/logrus"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/router"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/config"
"github.com/gin-gonic/contrib/ginrus"
...
...
@@ -15,23 +18,23 @@ import (
)
var
(
argPort
=
pflag
.
Int
(
"port"
,
8088
,
""
)
argPrefix
=
pflag
.
String
(
"prefix"
,
"/test
"
,
""
)
redis
Url
=
pflag
.
String
(
"redisUrl"
,
"redis://k8s.wodcloud.com:16379
"
,
""
)
redisTag
=
pflag
.
String
(
"redisTag"
,
"apaas-mesh-proxy
"
,
""
)
argPort
=
pflag
.
Int
(
"port"
,
8088
,
""
)
redisUrl
=
pflag
.
String
(
"redisUrl"
,
"redis://k8s.wodcloud.com:16379
"
,
""
)
redis
Tag
=
pflag
.
String
(
"redisTag"
,
"apaas-mesh-proxy
"
,
""
)
confPath
=
pflag
.
String
(
"confPath"
,
"/app/config/proxy.yaml
"
,
""
)
)
func
main
()
{
pflag
.
Parse
()
initEnv
()
initConfig
()
getProxyConf
()
server
()
}
func
server
()
error
{
config
.
Prefix
=
*
argPrefix
handler
:=
router
.
Load
(
ginrus
.
Ginrus
(
logrus
.
StandardLogger
(),
time
.
RFC3339
,
true
))
fmt
.
Println
(
fmt
.
Sprintf
(
":%d"
,
*
argPort
))
fmt
.
Println
(
fmt
.
Sprintf
(
"
Listen Server on
:%d"
,
*
argPort
))
return
http
.
ListenAndServe
(
fmt
.
Sprintf
(
":%d"
,
*
argPort
),
handler
,
...
...
@@ -49,5 +52,15 @@ func initEnv() {
func
initConfig
()
{
config
.
RedisTag
=
*
redisTag
config
.
RedisURL
=
*
redisUrl
config
.
Prefix
=
*
argPrefix
}
// 获取代理参数
func
getProxyConf
()
{
b
,
err
:=
ioutil
.
ReadFile
(
*
confPath
)
if
err
!=
nil
{
logrus
.
Error
(
err
)
return
}
json
.
Unmarshal
(
b
,
&
config
.
ProxyConf
)
fmt
.
Println
(
"代理参数:"
,
config
.
ProxyConf
)
}
src/router/router.go
View file @
a747a087
...
...
@@ -16,7 +16,6 @@ package router
import
(
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/config"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/handler"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/router/middleware/header"
"net/http"
...
...
@@ -29,7 +28,7 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
e
.
Use
(
header
.
Options
)
e
.
Use
(
header
.
Secure
)
e
.
Use
(
middleware
...
)
root
:=
e
.
Group
(
config
.
Prefix
)
root
:=
e
.
Group
(
"/"
)
{
root
.
GET
(
"/count"
,
handler
.
GetCount
)
root
.
Any
(
"/proxy/*action"
,
handler
.
Proxy
)
...
...
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