Update filewatch example
This commit is contained in:
@@ -1,26 +1,25 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/fsnotify/fsnotify"
|
|
||||||
"github.com/olahol/melody"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/fsnotify/fsnotify"
|
||||||
|
"github.com/olahol/melody"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
file := "file.txt"
|
file := "file.txt"
|
||||||
|
|
||||||
r := gin.Default()
|
|
||||||
m := melody.New()
|
m := melody.New()
|
||||||
w, _ := fsnotify.NewWatcher()
|
w, _ := fsnotify.NewWatcher()
|
||||||
|
|
||||||
r.GET("/", func(c *gin.Context) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
http.ServeFile(c.Writer, c.Request, "index.html")
|
http.ServeFile(w, r, "index.html")
|
||||||
})
|
})
|
||||||
|
|
||||||
r.GET("/ws", func(c *gin.Context) {
|
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
|
||||||
m.HandleRequest(c.Writer, c.Request)
|
m.HandleRequest(w, r)
|
||||||
})
|
})
|
||||||
|
|
||||||
m.HandleConnect(func(s *melody.Session) {
|
m.HandleConnect(func(s *melody.Session) {
|
||||||
@@ -40,5 +39,5 @@ func main() {
|
|||||||
|
|
||||||
w.Add(file)
|
w.Add(file)
|
||||||
|
|
||||||
r.Run(":5000")
|
http.ListenAndServe(":5000", nil)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user