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.
 
 
 

40 lines
653 B

package main
import (
"errors"
)
type PayloadType string
const (
PayloadTypeText PayloadType = "text"
PayloadTypeNotice PayloadType = "notice"
)
type Payload struct {
Type PayloadType `json:"type"`
Message string `json:"message"`
RoomID string `json:"roomID"`
}
func (p *Payload) Validate(defaultRoom *string) error {
if p.Type == "" {
p.Type = PayloadTypeText
}
if p.RoomID == "" && defaultRoom != nil {
p.RoomID = *defaultRoom
}
if p.Message == "" {
return errors.New("'message' is required")
}
if p.RoomID == "" {
return errors.New("'roomID' is required")
}
p.RoomID = getRoom(p.RoomID)
return nil
}