-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote.go
More file actions
47 lines (40 loc) · 1.02 KB
/
note.go
File metadata and controls
47 lines (40 loc) · 1.02 KB
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
package pknulms
import (
"encoding/json"
"errors"
"net/url"
)
// SendNote sends note to a person with given title and content.
func (c *Client) SendNote(to, title, content string) error {
target := "http://lms.pknu.ac.kr/ilos/message/insert_pop.acl"
params := url.Values{
"TITLE": {title},
"RECV_IDs": {to + "^"},
"CONTENT": {content},
"encoding": {"utf-8"},
}
resp, err := c.httpClient.PostForm(target, params)
if err != nil {
return err
}
defer resp.Body.Close()
var result struct {
IsError bool `json:"isError"`
Message string `json:"message"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return err
}
// Actually, it seems that an error cannot occur here
if result.IsError {
return errors.New(result.Message)
}
return nil
}
// MustSendNote sends note to a person with given title and content,
// panics when an error has occurred.
func (c *Client) MustSendNote(to, title, content string) {
if err := c.SendNote(to, title, content); err != nil {
panic(err)
}
}