mirror of
https://github.com/zr-hebo/sniffer-agent.git
synced 2025-10-10 15:09:19 +08:00
add get status api
This commit is contained in:
@@ -6,27 +6,44 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
_ "net/http/pprof"
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
hu "github.com/zr-hebo/util-http"
|
||||||
|
_ "net/http/pprof"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
communicatePort int
|
communicatePort int
|
||||||
|
router = mux.NewRouter()
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.IntVar(&communicatePort, "communicate_port", 8088, "http server port. Default is 8088")
|
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() {
|
func Server() {
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: ":" + strconv.Itoa(communicatePort),
|
Addr: "0.0.0.0:" + strconv.Itoa(communicatePort),
|
||||||
Handler: mux.NewRouter(),
|
|
||||||
IdleTimeout: time.Second * 5,
|
IdleTimeout: time.Second * 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
http.Handle("/", router)
|
||||||
if err := server.ListenAndServe(); err != nil {
|
if err := server.ListenAndServe(); err != nil {
|
||||||
panic(err)
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user