mirror of
https://github.com/zr-hebo/sniffer-agent.git
synced 2025-10-10 06:39:18 +08:00
add communicator api
This commit is contained in:
@@ -2,13 +2,13 @@ package communicator
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
hu "github.com/zr-hebo/util-http"
|
||||
_ "net/http/pprof"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const (
|
||||
THROW_PACKET_RATE = "throw_packet_rate"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -16,34 +16,15 @@ var (
|
||||
router = mux.NewRouter()
|
||||
)
|
||||
|
||||
var (
|
||||
configMapLock sync.RWMutex
|
||||
configMap map[string]configItem
|
||||
)
|
||||
|
||||
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)
|
||||
configMap = make(map[string]configItem)
|
||||
tprc := newThrowPacketRateConfig()
|
||||
configMap[tprc.name] = tprc
|
||||
}
|
||||
|
||||
func Server() {
|
||||
server := &http.Server{
|
||||
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"
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user