-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (33 loc) · 820 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
package main
import (
"fmt"
"log"
"net/http"
"os"
craigslist "github.com/tmunayyer/go-craigslist"
)
func init() {
setEvnironmentVariables()
}
func main() {
fs := http.FileServer(http.Dir("./dist"))
http.Handle("/", fs)
initializeAPI()
port := ":3000"
prodPort := os.Getenv("PORT")
if prodPort != "" {
port = ":" + prodPort
}
fmt.Println("listening on: localhost", port)
log.Fatal(http.ListenAndServe(port, nil))
}
func initializeAPI() {
cl := craigslist.NewClient("newyork")
db := newDBClient()
ps := newPollingService(cl, db)
api := newAPIService(cl, db, ps)
http.HandleFunc("/api/v1/search", api.handleSearch)
http.HandleFunc("/api/v1/listing", api.handleListing)
http.HandleFunc("/api/v1/metric", api.handleMetric)
http.HandleFunc("/api/v1/activityChart", api.handleActivityChart)
}