tank/payload.go
Marcus Noble 2a79d08e71
Correctly get room ID
Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
2021-12-05 15:30:58 +00:00

41 lines
653 B
Go

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
}