-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomments.go
36 lines (29 loc) · 835 Bytes
/
comments.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
package GoStack
import "net/http"
import "io/ioutil"
import "encoding/json"
//CommentStruct is a structure containing the basic data for a given
type CommentStruct struct {
baseURL string
site string
}
//NewCommentStruct instantiates an objects through which all functionality can be obtained
func NewCommentStruct(site string) CommentStruct {
comment := CommentStruct{"https://api.stackexchange.com/2.2/comments", site}
return comment
}
//GetComments makes a default call
func GetComments(site string) []Comment {
url := "https://api.stackexchange.com/2.2/comments" + "?site=" + site
resp, err := http.Get(url)
if err != nil {
println(err.Error())
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
println(err.Error())
}
var comments Response
json.Unmarshal(body, &comments)
return comments.Items
}