Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

get rid of duplicate json calls #1

Open
aktau opened this issue Apr 4, 2014 · 0 comments
Open

get rid of duplicate json calls #1

aktau opened this issue Apr 4, 2014 · 0 comments

Comments

@aktau
Copy link

aktau commented Apr 4, 2014

Well, you asked for it in your readme:

json_data, err := json.Marshal(message)
if err == nil {
    websocket.Message.Send(wsc.socket, string(json_data))
}

Could become:

websocket.JSON.Send(wsc.socket, message)

Because the go.net websocket implementation has a built-in JSON codec (which uses json.Marshal under the hood, of course). So that will make your code a bit more DRY.

Also you should check for errors:

if err := websocket.JSON.Send(wsc.socket, message); err != nil {
    log.Println("wsconnection: error, could not send json message, ", err)
    // or do something else if you want...
}
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant