-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.go
50 lines (39 loc) · 1.08 KB
/
handlers.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
49
50
package main
import (
"encoding/json"
"net/http"
)
func ViewAllRows(w http.ResponseWriter, r *http.Request) {
hashtags := ViewRows()
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(hashtags); err != nil {
panic(err)
}
}
func Positive(w http.ResponseWriter, r *http.Request) {
hashtag := SelectRandomHashtag("positive")
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(hashtag); err != nil {
panic(err)
}
}
func Negative(w http.ResponseWriter, r *http.Request) {
hashtag := SelectRandomHashtag("negative")
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(hashtag); err != nil {
panic(err)
}
}
func Updated(w http.ResponseWriter, r *http.Request) {
UpdateHashtags()
hashtags := ViewRows()
js, err := json.Marshal(hashtags)
if err != nil {
panic(err)
}
w.Header().Set("Content-Type", "application/json")
w.Write(js)
}