// This is a system for playing with SDN based openvswitches using a simple web
// interface. This project will be combined with a CLI version or probably just
// made compatible with a core version in the future.
-package vscpweb
+package main
import (
"fmt"
+ "html/template"
"net/http"
hh "healthHandlers"
- mh "managementHandlers"
- vh "virtualAPIHandlers"
- ch "controllerHandlers"
- sh "staticHandlers"
+ //mh "managementHandlers"
+ //vh "virtualAPIHandlers"
+ //ch "controllerHandlers"
+ //sh "staticHandlers"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)
-
func main() {
//create a new server and mount the handlers:
s := CreateNewServer()
s.MountHandlers()
+
+ //Handle the static files
+ fs := http.FileServer(http.Dir("./static/"))
+ s.Router.Handle("/static/*", http.StripPrefix("/static/", fs))
+
//staring up the server:
- http.ListenAndServe(":8000", s.Router)
+ http.ListenAndServe(":8001", s.Router)
}
type server struct {
//example:
//example of a get function and its handler
s.Router.Get("/example/{first}/{second:[0-9]+}", ExampleHandler)
+ s.Router.Get("/", indexHandler)
//Creating subrouters:
//healthRouter check on the health of nodes or main server
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "First: %v\nSecond: %v", var1, var2)
}
+
+func indexHandler(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ passarg := "some passing argument"
+ indexTemplate := template.Must(template.ParseFiles("templates/views/index.html"))
+ indexTemplate.Execute(w, passarg)
+
+}