Configure rendering connected clients on HTML
This commit is contained in:
parent
c7e1df3f81
commit
dbeceee204
|
@ -1,6 +1,7 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -11,6 +12,9 @@ var (
|
||||||
WebPort string = "8080"
|
WebPort string = "8080"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed templates/*
|
||||||
|
var templatesFolder embed.FS
|
||||||
|
|
||||||
func WebServer() {
|
func WebServer() {
|
||||||
p := viper.GetString("Server.WebPort")
|
p := viper.GetString("Server.WebPort")
|
||||||
if p != "" {
|
if p != "" {
|
||||||
|
@ -18,10 +22,15 @@ func WebServer() {
|
||||||
}
|
}
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
|
LoadHTMLFromEmbedFS(r, templatesFolder, "templates/*.html")
|
||||||
|
r.StaticFileFS("/style.css", "./templates/style.css", http.FS(templatesFolder))
|
||||||
r.GET("/", getRoot)
|
r.GET("/", getRoot)
|
||||||
r.Run(":" + WebPort)
|
r.Run(":" + WebPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRoot(c *gin.Context) {
|
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
|
clientList []*Client
|
||||||
)
|
)
|
||||||
|
|
||||||
func (I Instructions) Send(c net.Conn) {
|
|
||||||
message := "Do a flip!\n"
|
|
||||||
c.Write([]byte(message))
|
|
||||||
}
|
|
||||||
|
|
||||||
func Server() {
|
func Server() {
|
||||||
p := viper.GetString("Server.Port")
|
p := viper.GetString("Server.Port")
|
||||||
if p != "" {
|
if p != "" {
|
||||||
|
@ -59,12 +54,10 @@ func handleConn(conn net.Conn) {
|
||||||
}
|
}
|
||||||
client.Conn = conn
|
client.Conn = conn
|
||||||
fmt.Println("Got info from new user:", client.OS_username, client.OperatingSystem)
|
fmt.Println("Got info from new user:", client.OS_username, client.OperatingSystem)
|
||||||
clientList = append(clientList, client)
|
// for i, v := range clientList {
|
||||||
}
|
// fmt.Println(i, v)
|
||||||
|
//
|
||||||
func sendInstructions(conn net.Conn) {
|
// }
|
||||||
i := Instructions{}
|
|
||||||
i.Send(conn)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOS(conn net.Conn) (*Client, error) {
|
func getOS(conn net.Conn) (*Client, error) {
|
||||||
|
|
Loading…
Reference in New Issue