From 4a6e88464e39085c9335565d0a1402d0d7b6f84f Mon Sep 17 00:00:00 2001 From: hebo Date: Fri, 9 Aug 2019 19:55:07 +0800 Subject: [PATCH] add get status api --- communicator/config.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/communicator/config.go b/communicator/config.go index 53ae3c2..14f0371 100644 --- a/communicator/config.go +++ b/communicator/config.go @@ -6,27 +6,44 @@ import ( "strconv" "time" - _ "net/http/pprof" "github.com/gorilla/mux" + hu "github.com/zr-hebo/util-http" + _ "net/http/pprof" ) var ( communicatePort int + router = mux.NewRouter() ) func init() { flag.IntVar(&communicatePort, "communicate_port", 8088, "http server port. Default is 8088") + + router.Path("/get_status").Methods("GET").HandlerFunc(getStatus) + router.Path("/set_config").Methods("POST").HandlerFunc(setConfig) } func Server() { server := &http.Server{ - Addr: ":" + strconv.Itoa(communicatePort), - Handler: mux.NewRouter(), + Addr: "0.0.0.0:" + strconv.Itoa(communicatePort), IdleTimeout: time.Second * 5, } + http.Handle("/", router) if err := server.ListenAndServe(); err != nil { panic(err) } } +func getStatus(resp http.ResponseWriter, req *http.Request) { + mp := hu.NewMouthpiece(resp) + defer mp.Convey() + mp.Data = "OK" +} + +func setConfig(resp http.ResponseWriter, req *http.Request) { + mp := hu.NewMouthpiece(resp) + defer mp.Convey() + mp.Data = "OK" +} +