Created
February 12, 2020 00:56
-
-
Save mosleim/3a3894813e012b601445e3e170013178 to your computer and use it in GitHub Desktop.
coba websocket ke nats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (h *Handler) dksocket(c *gin.Context) { | |
token := h.extractClaim(c) | |
conn, err := wsupgrader.Upgrade(c.Writer, c.Request, nil) | |
nc, _ := nats.Connect(nats.DefaultURL) | |
nc.Subscribe(token.UserID, func(m *nats.Msg) { | |
conn.WriteMessage(1, m.Data) // meneruskan subcribe ke websocket. potensi panic ga?? | |
}) | |
nc.Subscribe("pengumuman", func(m *nats.Msg) { | |
conn.WriteMessage(1, m.Data) // meneruskan subcribe ke websocket. potensi panic ga?? | |
}) | |
for { | |
t, msg, err := conn.ReadMessage() | |
fmt.Println(t, msg, err) | |
conn.WriteMessage(t, msg) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment