forked from taiyoh/graphqlws-subscription-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.go
More file actions
33 lines (29 loc) · 666 Bytes
/
request.go
File metadata and controls
33 lines (29 loc) · 666 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package gss
import (
"encoding/json"
"errors"
)
type RequestData struct {
Users []string `json:"users"`
Channel string `json:"channel"`
Payload interface{} `json:"payload"`
}
func (d *RequestData) Validate() error {
if d.Channel == "" {
return errors.New("require channel")
}
if d.Payload == nil {
return errors.New("require payload")
}
return nil
}
func NewRequestDataFromBytes(b []byte) (*RequestData, error) {
data := &RequestData{}
if err := json.Unmarshal(b, data); err != nil {
return nil, errors.New("cannot parse invalid JSON request data")
}
if err := data.Validate(); err != nil {
return nil, err
}
return data, nil
}