-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (50 loc) · 1.41 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
56
57
58
59
60
61
package main
import (
"log"
"net/http"
"os"
api "github.com/hootsuite/google-calendar-app-sample/api/planned-content"
"github.com/joho/godotenv"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
cal "google.golang.org/api/calendar/v3"
)
func main() {
env, _ := godotenv.Read(".env")
CLIENT_ID := os.Getenv("CLIENT_ID")
if CLIENT_ID == "" {
CLIENT_ID = env["CLIENT_ID"]
if CLIENT_ID == "" {
log.Fatal("CLIENT_ID is required")
}
}
CLIENT_SECRET := os.Getenv("CLIENT_SECRET")
if CLIENT_SECRET == "" {
CLIENT_SECRET = env["CLIENT_SECRET"]
if CLIENT_SECRET == "" {
log.Fatal("CLIENT_SECRET is required")
}
}
// Get the client id and secret from google cloud credential.
// url: https://console.cloud.google.com/apis/credentials
// access them from environment variable
// Oauth config manage the OAuth flow. You have to register
// the redirect url in the OAuth provider. For the endpoint,
// there are many provider specific package inside the
// golang.org/x/oauth2 package
conf := &oauth2.Config{
ClientID: os.Getenv("CLIENT_ID"),
ClientSecret: os.Getenv("CLIENT_SECRET"),
//: "http://localhost:8000/auth/callback",
Scopes: []string{cal.CalendarReadonlyScope},
Endpoint: google.Endpoint,
}
server := api.NewServer(conf)
r := http.NewServeMux()
h := api.HandlerFromMux(server, r)
s := &http.Server{
Handler: h,
Addr: "0.0.0.0:8000",
}
log.Fatal(s.ListenAndServe())
}