room.go 440 B

12345678910111213141516171819202122232425
  1. package model
  2. import (
  3. "fmt"
  4. "net/url"
  5. )
  6. const (
  7. // NoRoom default no room key
  8. NoRoom = "noroom"
  9. )
  10. // EncodeRoomKey encode a room key.
  11. func EncodeRoomKey(business string, room string) string {
  12. return fmt.Sprintf("%s://%s", business, room)
  13. }
  14. // DecodeRoomKey decode room key.
  15. func DecodeRoomKey(key string) (string, string, error) {
  16. u, err := url.Parse(key)
  17. if err != nil {
  18. return "", "", err
  19. }
  20. return u.Scheme, u.Host, nil
  21. }