Created
June 25, 2018 02:43
-
-
Save syfun/cd6af58dd6412760653cfc6a1866226e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"log" | |
"github.com/gorilla/websocket" | |
) | |
type Message struct { | |
Action string `json:"action"` | |
Data interface{} `json:"data,omitempty"` | |
} | |
func main() { | |
conn, _, err := websocket.DefaultDialer.Dial("ws://localhost:10001/ws", nil) | |
if err != nil { | |
log.Fatal("dial: ", err) | |
} | |
defer conn.Close() | |
msg := Message{"connect", "hello"} | |
conn.WriteJSON(msg) | |
var rst Message | |
conn.ReadJSON(&rst) | |
log.Printf("recv: %s", rst) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment