diff --git a/cmd/httpServer.go b/cmd/httpServer.go index b6a7440..84c02a2 100644 --- a/cmd/httpServer.go +++ b/cmd/httpServer.go @@ -1,6 +1,7 @@ package cmd import ( + "embed" "net/http" "github.com/gin-gonic/gin" @@ -11,6 +12,9 @@ var ( WebPort string = "8080" ) +//go:embed templates/* +var templatesFolder embed.FS + func WebServer() { p := viper.GetString("Server.WebPort") if p != "" { @@ -18,10 +22,15 @@ func WebServer() { } gin.SetMode(gin.ReleaseMode) r := gin.Default() + LoadHTMLFromEmbedFS(r, templatesFolder, "templates/*.html") + r.StaticFileFS("/style.css", "./templates/style.css", http.FS(templatesFolder)) r.GET("/", getRoot) r.Run(":" + WebPort) } func getRoot(c *gin.Context) { - c.String(http.StatusOK, "Hello world!\n") + c.HTML(http.StatusOK, "templates/index.html", gin.H{ + "UserAgent": c.Request.UserAgent(), + "Clients": clientList, + }) } diff --git a/cmd/serverFunc.go b/cmd/serverFunc.go index 610fca7..2a7ce15 100644 --- a/cmd/serverFunc.go +++ b/cmd/serverFunc.go @@ -24,11 +24,6 @@ var ( clientList []*Client ) -func (I Instructions) Send(c net.Conn) { - message := "Do a flip!\n" - c.Write([]byte(message)) -} - func Server() { p := viper.GetString("Server.Port") if p != "" { @@ -59,12 +54,10 @@ func handleConn(conn net.Conn) { } client.Conn = conn fmt.Println("Got info from new user:", client.OS_username, client.OperatingSystem) - clientList = append(clientList, client) -} - -func sendInstructions(conn net.Conn) { - i := Instructions{} - i.Send(conn) + // for i, v := range clientList { + // fmt.Println(i, v) + // + // } } func getOS(conn net.Conn) (*Client, error) {