tank/payload.go

41 lines
653 B
Go
Raw Normal View History

2021-07-07 10:05:36 +00:00
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)
2021-07-07 10:05:36 +00:00
return nil
}