Browse Source

update 默认转发路由 沿用原有请求路由地址

pull/2/head
lucas 2 months ago
parent
commit
da5078826c
  1. 4
      config/configStruct.go
  2. 4
      configFiles/config_转发http2axy60000端口.json
  3. 10
      consumers/consumerHTTP_PRPXY.go
  4. 2
      dbHelper/apiServerHelper.go

4
config/configStruct.go

@ -40,8 +40,8 @@ type HttpConfig struct {
} }
type ApiServerConfig struct { type ApiServerConfig struct {
Port uint `json:"port"` Port uint `json:"port"`
Routes map[string]string `json:"routes"` Routers map[string]string `json:"routers"`
} }
type Token struct { type Token struct {

4
configFiles/config_转发http2axy60000端口.json

@ -6,7 +6,7 @@
"port": 7000, "port": 7000,
"userName": "anQuanDai", "userName": "anQuanDai",
"password": "123", "password": "123",
"routes": { "routers": {
"route1": "POST /upload/work/ABStatus", "route1": "POST /upload/work/ABStatus",
"route2": "POST /upload/work/ABHeart" "route2": "POST /upload/work/ABHeart"
} }
@ -14,7 +14,7 @@
}, },
"out": { "out": {
"httpPost": { "httpPost": {
"url": "http://218.3.126.49:60000/upload", "url": "http://218.3.126.49:60000",
"method": "post" "method": "post"
} }
} }

10
consumers/consumerHTTP_PRPXY.go

@ -44,7 +44,7 @@ func (the *consumerHttpProxy) InputInitial() error {
//数据入口 //数据入口
the.InApiServer = dbHelper.NewApiServer( the.InApiServer = dbHelper.NewApiServer(
the.Info.IoConfig.In.ApiServer.Port, the.Info.IoConfig.In.ApiServer.Port,
the.Info.IoConfig.In.ApiServer.Routes, the.Info.IoConfig.In.ApiServer.Routers,
) )
the.InApiServer.Initial() the.InApiServer.Initial()
return nil return nil
@ -59,9 +59,11 @@ func (the *consumerHttpProxy) OutputInitial() error {
} }
func (the *consumerHttpProxy) Work() { func (the *consumerHttpProxy) Work() {
go func() { go func() {
router := "POST /onData" for _, router := range the.Info.IoConfig.In.ApiServer.Routers {
the.InApiServer.RouteRegister(router, the.onData) the.InApiServer.RouteRegister(router, the.onData)
}
the.InApiServer.Run() the.InApiServer.Run()
}() }()
} }
func (the *consumerHttpProxy) onData(w http.ResponseWriter, r *http.Request) { func (the *consumerHttpProxy) onData(w http.ResponseWriter, r *http.Request) {
@ -86,6 +88,8 @@ func (the *consumerHttpProxy) onData(w http.ResponseWriter, r *http.Request) {
params := map[string]string{ params := map[string]string{
"id": id, "id": id,
} }
//沿用请求路由
the.outHttpPost.Url += r.URL.String()
resp, err := the.outHttpPost.HttpPostWithParams(string(body), params) resp, err := the.outHttpPost.HttpPostWithParams(string(body), params)
if err != nil { if err != nil {
return return

2
dbHelper/apiServerHelper.go

@ -30,7 +30,7 @@ func (the *ApiServerHelper) Initial() {
Addr: fmt.Sprintf(":%d", the.port), Addr: fmt.Sprintf(":%d", the.port),
} }
the.routeRegister() //the.routeRegister()
} }
func (the *ApiServerHelper) Run() { func (the *ApiServerHelper) Run() {

Loading…
Cancel
Save