package ws import ( "encoding/json" "errors" "gopkg.in/olahol/melody.v1" ) func WriteJsonWithSession(s *melody.Session, body interface{}) error { if s == nil { return errors.New("session is nil") } bs, err := json.Marshal(body) if err != nil { return err } return s.Write(bs) }