add websockets
This commit is contained in:
@@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user