-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (37 loc) · 940 Bytes
/
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
package main
import (
"github.com/gorilla/mux"
"log"
"net/http"
"os"
)
const (
PORT = ":8080"
INDEX = "templates/index.html"
)
var GlobalStore = map[string]int{}
func main() {
go checker()
if len(os.Args) == 2 {
cliGetGist()
}
log.Printf("Started Github Public Gist Query Application on port [%v] ", PORT)
router := mux.NewRouter()
router.HandleFunc("/", RootHandler)
router.HandleFunc("/query", QueryHandler)
router.HandleFunc("/api", ApiHandler).Methods("POST")
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
http.Handle("/", router)
log.Fatal(http.ListenAndServe(PORT, nil))
}
// retrive the public gists for a user passed as a commandline argument
func cliGetGist() {
user := os.Args[1]
g, err := GetGist(user)
if err != nil {
log.Println(err)
}
if _, exists := GlobalStore[user]; !exists {
GlobalStore[user] = g.Counter
}
}