-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
51 lines (43 loc) · 1.06 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
package main
import (
"fmt"
"github.com/CrowdSurge/banner"
"github.com/gorilla/mux"
"log"
"net/http"
"os"
"strconv"
"video-feed/kafka"
"video-feed/redis"
)
func main() {
if len(os.Args) > 2{
if os.Args[1] == "populate"{
numRecords,err := strconv.Atoi(os.Args[2])
if err!=nil{
fmt.Println( "Could not convert arguments provided, hence creating four entries")
numRecords = 4
}
redis.Populate(numRecords)
return
}
}
router := mux.NewRouter()
router.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Pong !!\n"))
})
router.HandleFunc("/detail/{id}", VideoHandler)
router.HandleFunc("/like/{id}", LikeHandler)
router.HandleFunc("/popular/{num[0-9]+}", PopularHandler)
http.Handle("/", router)
banner.Print("video-feed")
log.Println("Initializing redis pool: ")
redis.Init()
go kafka.InitProducer()
go kafka.Consumer([]string{"likes", "upload"})
log.Println("Video-Feed Listening on :4000")
err := http.ListenAndServe(":4000", nil)
if err != nil {
log.Printf("Server error %v :", err)
}
}