Skip to content

Commit

Permalink
fix: error connection on CheckOrigin
Browse files Browse the repository at this point in the history
  • Loading branch information
kenriortega committed Nov 8, 2021
1 parent 4ebc551 commit 0f8edc0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions internal/mngt/handlers/mngt.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
ReadBufferSize: 1024,
WriteBufferSize: 1024,
EnableCompression: false,
CheckOrigin: func(*http.Request) bool { return true },
}
)

Expand Down Expand Up @@ -76,6 +77,7 @@ func writeResponse(w http.ResponseWriter, code int, data interface{}) {
}

func (mh MngtHandler) WssocketHandler(w http.ResponseWriter, r *http.Request) {

query := r.URL.Query()
ds := query.Get("ds")
if ds == "" {
Expand All @@ -89,6 +91,7 @@ func (mh MngtHandler) WssocketHandler(w http.ResponseWriter, r *http.Request) {
defer c.Close()

for {

mt, message, err := c.ReadMessage()
if err != nil {
log.Println("read:", err)
Expand All @@ -105,26 +108,24 @@ func (mh MngtHandler) WssocketHandler(w http.ResponseWriter, r *http.Request) {
}
err = c.WriteMessage(mt, bytes)
if err != nil {
log.Println("write:", err)
log.Println("write endpoints:", err)

}
durations, err := time.ParseDuration(ds)
if err != nil {
err = c.WriteMessage(mt, []byte(err.Error()))
if err != nil {
log.Println("write:", err)

log.Println("write durations:", err)
}
}
time.Sleep(durations)
}

default:
err = c.WriteMessage(mt, []byte("CMD not found"))
if err != nil {
log.Println("write:", err)

log.Println("write default:", err)
}
}

}
}

0 comments on commit 0f8edc0

Please sign in to comment.