-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.go
59 lines (46 loc) · 1.12 KB
/
home.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
56
57
58
59
// Copyright (c) Bluebeam Inc. All rights reserved.
//
// Licensed under the MIT License. See LICENSE in the project root for license information.
package main
import (
"encoding/json"
"fmt"
"html/template"
"net/http"
)
func homePage(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/favicon.ico" {
return
}
html, err := Asset("assets/home.html")
if err != nil {
redirectToError(w, r, err)
return
}
t, _ := template.New("login").Parse(string(html))
ctx := r.Context()
u := ctx.Value("user").(user)
client := env.OAuthConfig.Client(ctx, u.Token)
req, err := http.NewRequest("GET", "https://studioapi.bluebeam.com/publicapi/v1/projects", nil)
resp, err := client.Do(req)
if err != nil {
redirectToError(w, r, err)
return
}
if ok, err := checkHTTPResponse(resp); !ok {
redirectToError(w, r, err)
return
}
projects := ProjectsResponse{}
err = json.NewDecoder(resp.Body).Decode(&projects)
if err != nil {
redirectToError(w, r, err)
return
}
fmt.Println(projects)
homeData := struct {
UserID string
Projects []*Project
}{u.UserID, projects.Projects}
t.Execute(w, homeData)
}