/
main.go
62 lines (49 loc) · 1.31 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
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"strconv"
"time"
"github.com/gocraft/work/webui"
"github.com/gomodule/redigo/redis"
)
var (
redisHostPort = flag.String("redis", ":6379", "redis hostport")
redisDatabase = flag.String("database", "0", "redis database")
redisNamespace = flag.String("ns", "work", "redis namespace")
webHostPort = flag.String("listen", ":5040", "hostport to listen for HTTP JSON API")
)
func main() {
flag.Parse()
fmt.Println("Starting workwebui:")
fmt.Println("redis = ", *redisHostPort)
fmt.Println("database = ", *redisDatabase)
fmt.Println("namespace = ", *redisNamespace)
fmt.Println("listen = ", *webHostPort)
database, err := strconv.Atoi(*redisDatabase)
if err != nil {
fmt.Printf("Error: %v is not a valid database value", *redisDatabase)
return
}
pool := newPool(*redisHostPort, database)
server := webui.NewServer(*redisNamespace, pool, *webHostPort)
server.Start()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
<-c
server.Stop()
fmt.Println("\nQuitting...")
}
func newPool(addr string, database int) *redis.Pool {
return &redis.Pool{
MaxActive: 3,
MaxIdle: 3,
IdleTimeout: 240 * time.Second,
Dial: func() (redis.Conn, error) {
return redis.DialURL(addr, redis.DialDatabase(database))
},
Wait: true,
}
}