example router
authorjosuer08 <josuer08@gmail.com>
Tue, 30 Aug 2022 23:26:40 +0000 (19:26 -0400)
committerjosuer08 <josuer08@gmail.com>
Tue, 30 Aug 2022 23:26:40 +0000 (19:26 -0400)
go.mod [new file with mode: 0644]
go.sum [new file with mode: 0644]
main.go [new file with mode: 0644]

diff --git a/go.mod b/go.mod
new file mode 100644 (file)
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 (file)
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 (file)
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"])
+}