message.go

on kitten's pastes | raw

expires: 27 Apr, 2024

 1func (m *Message) UnmarshalJSON(b []byte) error {
 2	var msg Message
 3
 4	if err := json.Unmarshal(b, &msg); err != nil {
 5		return err
 6	}
 7
 8	if msg.Command == "" {
 9		return errors.New("command is empty")
10	}
11
12	if len(msg.Data.Details) > 128 || len(msg.Data.State) > 128 {
13		return errors.New("details or state cannot be longer than 128 characters")
14	}
15
16	*m = msg
17	return nil
18}