diff --git a/configFiles/config_转发http2axy60000端口.json b/configFiles/config_转发http2axy60000端口.json new file mode 100644 index 0000000..a45dd7a --- /dev/null +++ b/configFiles/config_转发http2axy60000端口.json @@ -0,0 +1,20 @@ +{ + "consumer": "consumerHttpProxy", + "ioConfig": { + "in": { + "apiServer": { + "port": 7000, + "userName": "anQuanDai", + "password": "123", + "routes": { + "route1": "POST /upload/work/ABStatus", + "route2": "POST /upload/work/ABHeart" + } + } + }, + "out": { + "url": "http://127.0.0.1:4009/write", + "method": "post" + } + } +} \ No newline at end of file diff --git a/configFiles/config_安心云设备数据_最新同步.json b/configFiles/弃用备份/config_安心云设备数据_最新同步.json similarity index 100% rename from configFiles/config_安心云设备数据_最新同步.json rename to configFiles/弃用备份/config_安心云设备数据_最新同步.json diff --git a/configFiles/弃用备份/config_转发http2axy60000端口.json b/configFiles/弃用备份/config_转发http2axy60000端口.json deleted file mode 100644 index d01b113..0000000 --- a/configFiles/弃用备份/config_转发http2axy60000端口.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "consumer": "consumerHttpProxy", - "ioConfig": { - "in": { - "httpServer": { - "port": 19700, - "userName": "goInOut", - "password": "", - "routes": [ - "upload/uds/+", - "upload/ZD/+" - ] - } - }, - "out": { - "url": "http://127.0.0.1:4009/write?u=mingyuexia_wkd&p=mingyuexia_wkd&db=MingYueXia_Bridge&rp=autogen", - "method": "post" - } - } -} \ No newline at end of file diff --git a/dbHelper/apiServerHelper.go b/dbHelper/apiServerHelper.go index 665d224..06c5d79 100644 --- a/dbHelper/apiServerHelper.go +++ b/dbHelper/apiServerHelper.go @@ -7,40 +7,43 @@ import ( ) type ApiServerHelper struct { - mux *http.ServeMux - route map[string]string - port uint + mux *http.ServeMux + routes map[string]string + port uint } func NewApiServer(port uint, routes map[string]string) *ApiServerHelper { return &ApiServerHelper{ - mux: http.NewServeMux(), - route: routes, - port: port, + mux: http.NewServeMux(), + routes: routes, + port: port, } } func (the *ApiServerHelper) Initial() { the.mux = http.NewServeMux() + // 创建 HTTP 服务器 ser := http.Server{ Handler: the.mux, Addr: fmt.Sprintf(":%d", the.port), } + + the.routeRegister() + log.Printf("apiServer监听端口 %d", the.port) go log.Fatal(ser.ListenAndServe()) } func (the *ApiServerHelper) routeRegister() { - the.mux.HandleFunc("GET /nodeList", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") - s := `{"a":1}` - fmt.Fprintf(w, s) - }) - - the.mux.HandleFunc("GET /namespaceList", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") - s := `{"b":1}` - fmt.Fprintf(w, s) - }) + + for _, rote := range the.routes { + the.mux.HandleFunc(rote, func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + s := fmt.Sprintf(`{"rote":"%s","resp":"安全带状态应答"}`, rote) + println("收到请求", rote) + fmt.Fprintf(w, s) + }) + log.Printf("注册路由 %s", rote) + } } diff --git a/go.mod b/go.mod index 685dc9a..e69a73f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module goInOut -go 1.21 +go 1.22 require ( github.com/IBM/sarama v1.43.3