-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (34 loc) · 863 Bytes
/
Copy pathmain.go
File metadata and controls
44 lines (34 loc) · 863 Bytes
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
package main
import (
"fmt"
"log"
"net/http"
"github.com/zmb3/spotify"
)
var html = `
<br/>
`
var (
authUrlChan = make(chan string, 1)
endpoint = getEnv("ARTIFY_ENDPOINT", "localhost")
user *spotify.PrivateUser
)
func main() {
// Callback for authenticating the user
http.HandleFunc("/callback", handleAuthCallback)
// Receive the auth URL and create a redirect on /auth
http.HandleFunc("/auth", authRedirectHandler)
// Once authenticated, kick off the main goroutine for the program
go func() {
client := getClientForUser()
user, err := client.CurrentUser()
if err != nil {
log.Fatal(err)
}
fmt.Println("Logged in as:", user.ID)
go monitorForActiveSession(client)
}()
err := http.ListenAndServe(fmt.Sprintf("%s:8080", endpoint), nil)
fmt.Println("Artify started on port 8080")
fmt.Printf("Error: %s\n", err)
}