-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
55 lines (46 loc) · 1.24 KB
/
main.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
51
52
53
54
55
package main
import (
"io"
"log"
"net/http"
"os"
)
func main() {
p := os.Getenv("PORT")
if p == "" {
p = "8080"
}
p = ":" + p
http.HandleFunc("/campaign", func(w http.ResponseWriter, r *http.Request) {
res, err := http.Get("https://api.patreon.com/campaigns/400650")
if err != nil {
log.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
defer res.Body.Close()
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json")
if _, err := io.Copy(w, res.Body); err != nil {
log.Println(err)
}
})
http.HandleFunc("/events", func(w http.ResponseWriter, r *http.Request) {
u := "https://api.meetup.com/2/events?&sign=true&photo-host=public&group_urlname=devICT&limited_events=false&fields=series&status=upcoming&page=20"
res, err := http.Get(u)
if err != nil {
log.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
defer res.Body.Close()
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(res.StatusCode)
if _, err := io.Copy(w, res.Body); err != nil {
log.Println(err)
}
})
log.Println("Listening to", p)
log.Fatal(http.ListenAndServe(p, nil))
}