You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
293 B

5 years ago
  1. package ws
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "gopkg.in/olahol/melody.v1"
  6. )
  7. func WriteJsonWithSession(s *melody.Session, body interface{}) error {
  8. if s == nil {
  9. return errors.New("session is nil")
  10. }
  11. bs, err := json.Marshal(body)
  12. if err != nil {
  13. return err
  14. }
  15. return s.Write(bs)
  16. }