GoのWebソケットを使用してチャットアプリケーションを作成しています。GoでGobのWebソケットをエンコードする
複数のチャットルームがあり、チャットルームに接続されているすべてのウェブソケットをRedisリストに保存することが考えられます。
RedisのWebソケットを格納して取得するには、それらをエンコード/デコードする必要があります(thisの質問に従います)。私はそれにgobを使用できると思っていました。
Redisにはgithub.com/garyburd/redigo/redis
、websocketライブラリにはgithub.com/gorilla/websocket
を使用しています。
My機能は、次のようになります。
func addWebsocket(room string, ws *websocket.Conn) {
conn := pool.Get()
defer conn.Close()
enc := gob.NewEncoder(ws)
_, err := conn.Do("RPUSH", room, enc)
if err != nil {
panic(err.Error())
}
}
しかし、私はこのエラーを取得しています:
cannot use ws (type *websocket.Conn) as type io.Writer in argument to gob.NewEncoder: *websocket.Conn does not implement io.Writer (missing Write method) have websocket.write(int, time.Time, ...[]byte) error want Write([]byte) (int, error)
をこのエラーは何を意味するのでしょうか? *websocket.Conn
のエンコーディングの考え方が間違っているか型変換が必要ですか?