add websockets

This commit is contained in:
2025-12-03 11:31:36 -06:00
parent 4d669317c4
commit 00ba06de53
8 changed files with 87 additions and 1 deletions

View File

@@ -8,14 +8,21 @@ import (
"os"
"path/filepath"
"strings"
"time"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
)
type DeleteSelected struct {
Svgs []string `json:"svgs" binding:"required"`
}
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
}
func main() {
router := gin.Default()
funcMap := template.FuncMap{
@@ -80,6 +87,23 @@ func main() {
c.HTML(200, "create-icon.html", nil)
})
router.GET("/ws", func(c *gin.Context) {
conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
if err != nil {
log.Panicln("error upgrading ws: ", err)
return
}
defer conn.Close()
for {
conn.WriteMessage(websocket.TextMessage, []byte("Hello Socket"))
time.Sleep(time.Second)
}
})
router.GET("/ws-example", func(c *gin.Context) {
c.HTML(200, "ws-example.html", nil)
})
router.POST("/prompt-icon", func(c *gin.Context) {
var form struct {
Prompt string `form:"prompt" binding:"required"`