/
gored.go
47 lines (38 loc) · 1.05 KB
/
gored.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
package main
import (
"fmt"
"github.com/Jkolios/GoRed/handlers"
"github.com/mediocregopher/radix.v2/redis"
"log"
"net/http"
"os"
"os/signal"
)
type connectionDetails struct {
host, port string
}
func initConnection(connDetails connectionDetails) *redis.Client {
// Connection Establishment
client, err := redis.Dial("tcp", connDetails.host+":"+connDetails.port)
if err != nil {
fmt.Println("Error while connecting:" + err.Error())
return nil
}
return client
}
func main() {
// Redis connection init
redisConnDetails := connectionDetails{"jspi2.local", " 6379"}
client := initConnection(redisConnDetails)
defer client.Close()
// HTTP server init
httpConnDetails := connectionDetails{host: "", port: "8080"}
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, os.Interrupt, os.Kill)
var handler handlers.SimpleRedisHandler
handler.Client = client
go handler.StoreCount(signalChannel)
handler.GetCurrent()
http.Handle("/", &handler)
log.Fatal(http.ListenAndServe(httpConnDetails.host+":"+httpConnDetails.port, nil))
}