-
Notifications
You must be signed in to change notification settings - Fork 21
/
comment.go
48 lines (42 loc) · 1.05 KB
/
comment.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package kintone
import (
"encoding/json"
"errors"
)
//
const (
ConstCommentMentionTypeGroup = "GROUP"
ConstCommentMentionTypeDepartment = "ORGANIZATION"
ConstCommentMentionTypeUser = "USER"
)
// ObjMentions structure
type ObjMention struct {
Code string `json:"code"`
Type string `json:"type"`
}
// ObjCreator structure
type ObjCreator struct {
Name string `json:"name"`
Code string `json:"code"`
}
// Comment structure
type Comment struct {
Id string `json:"id"`
Text string `json:"text"`
CreatedAt string `json:"createdAt"`
Creator *ObjCreator `json:"creator"`
Mentions []*ObjMention `json:"mentions"`
}
// DecodeRecordComments decodes JSON response for comment api
func DecodeRecordComments(b []byte) ([]Comment, error) {
var comments struct {
MyComments []Comment `json:"comments"`
Older bool `json:"older"`
Newer bool `json:"newer"`
}
err := json.Unmarshal(b, &comments)
if err != nil {
return nil, errors.New("Invalid JSON format")
}
return comments.MyComments, nil
}