From 0af9b005392fc6021e57c10c31d68800e845a7db Mon Sep 17 00:00:00 2001 From: josuer08 Date: Tue, 30 Aug 2022 19:26:40 -0400 Subject: [PATCH 1/1] example router --- go.mod | 5 +++++ go.sum | 2 ++ main.go | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..19e8587 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module VSCPweb + +go 1.19 + +require github.com/gorilla/mux v1.8.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5350288 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= +github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= diff --git a/main.go b/main.go new file mode 100644 index 0000000..24bb244 --- /dev/null +++ b/main.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "net/http" + + "github.com/gorilla/mux" +) + +func main() { + + //example of simple http router, fased out in favor of gorilla mux + //http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + //fmt.Fprintf(w, "Hello World!") + //}) + //http.ListenAndServe(":8000", nil) + + + + r := mux.NewRouter() + r.HandleFunc("/example/{first}/{second:[0-9]+}", exampleHandler) + //r.HandleFunc("/", ) + //r.HandleFunc("/access", ) + //r.HandleFunc("/stats", ) + //r.HandleFunc("/topology", ) + //r.HandleFunc("/health", ) + //r.HandleFunc("/free", )//probably do this with server side or sockets + //r.HandleFunc("/flowdel", )//this is an external request + //r.HandleFunc("/mpstat", ) + //r.HandleFunc("/ifstat", ) + //r.HandleFunc("/showtemp", ) + //r.HandleFunc("/gettopo", ) + //r.HandleFunc("/net", ) + //r.HandleFunc("/rpiping", )//workerping + //r.HandleFunc("/nodes", ) + //r.HandleFunc("/statusnodes", ) + //r.HandleFunc("/intfs", ) + //r.HandleFunc("/iperf", ) + //r.HandleFunc("/pingall", ) + //r.HandleFunc("/placement", ) + //r.HandleFunc("/getvsorcdata", ) + //r.HandleFunc("/getcontrollerdata", ) + //r.HandleFunc("/resetflows", ) + //r.HandleFunc("/listswitch", ) + //r.HandleFunc("/status", ) + //r.HandleFunc("/tablestatus", ) + //r.HandleFunc("/portsdesc", ) + //r.HandleFunc("/portsstat", ) + //r.HandleFunc("/startcontroller", ) + //r.HandleFunc("/startcontrollerrouter", ) + //r.HandleFunc("/stopcontroller", ) + //r.HandleFunc("/sendcommand", ) + //r.HandleFunc("/cancel", ) + //r.HandleFunc("/startvsorc", ) + //r.HandleFunc("/stopvsorc", ) + http.Handle("/", r) + http.ListenAndServe(":8000", nil) + + + +} + +func exampleHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, "First: %v\nSecond: %v", vars["first"], vars["second"]) +} -- 2.25.1