Configure rendering connected clients on HTML
This commit is contained in:
parent
c7e1df3f81
commit
dbeceee204
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue