Skip to content

Commit

Permalink
checking user id and using string builder instead of string + in real…
Browse files Browse the repository at this point in the history
…time endpoint
  • Loading branch information
sairahul1526 committed Jun 6, 2020
1 parent 836714f commit e46a061
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions realtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("wsHandler", err)
return
}
if checkUserID(r.FormValue("user_id")) {
if !checkUserID(r.FormValue("user_id")) {
ws.Close()
fmt.Println("wsHandler", "User not found", r.FormValue("user_id"))
return
Expand All @@ -35,21 +35,23 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
}()

if len(r.FormValue("tickers")) > 0 {
var send string
var send strings.Builder
active := true
for {
if active {
select {
case t := <-ticker.C:
for _, val := range getValuesRedis(stocks) {
send += val.(string) + "#"
if val != nil {
send.WriteString(val.(string) + "#")
}
}
err := ws.WriteMessage(websocket.TextMessage, []byte(send))
err := ws.WriteMessage(websocket.TextMessage, []byte(send.String()))
if err != nil {
fmt.Println("realtime", t, err)
active = false
}
send = ""
send.Reset()
}
} else {
break
Expand Down

0 comments on commit e46a061

Please sign in to comment.