util.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Discordgo - Discord bindings for Go
  2. // Available at https://github.com/bwmarrin/discordgo
  3. // Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>. All rights reserved.
  4. // Use of this source code is governed by a BSD-style
  5. // license that can be found in the LICENSE file.
  6. // This file contains utility functions for the discordgo package. These
  7. // functions are not exported and are likely to change substantially in
  8. // the future to match specific needs of the discordgo package itself.
  9. package discordgo
  10. import (
  11. "bytes"
  12. "encoding/json"
  13. "fmt"
  14. )
  15. // printEvent prints out a WSAPI event.
  16. func printEvent(e *Event) {
  17. fmt.Println(fmt.Sprintf("Event. Type: %s, State: %d Operation: %d Direction: %d", e.Type, e.State, e.Operation, e.Direction))
  18. printJSON(e.RawData)
  19. }
  20. // printJSON is a helper function to display JSON data in a easy to read format.
  21. func printJSON(body []byte) {
  22. var prettyJSON bytes.Buffer
  23. error := json.Indent(&prettyJSON, body, "", "\t")
  24. if error != nil {
  25. fmt.Print("JSON parse error: ", error)
  26. }
  27. fmt.Println(string(prettyJSON.Bytes()))
  28. }