-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (34 loc) · 804 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
package main
import (
"log"
"net/http"
"os"
"time"
"github.com/gomodule/redigo/redis"
"github.com/gorilla/mux"
)
var pool *redis.Pool
func main() {
redisUrl := getEnv("REDIS_URL", "localhost:6379")
pool = &redis.Pool{
MaxIdle: 10,
IdleTimeout: 240 * time.Second,
Dial: func() (redis.Conn, error) {
return redis.Dial("tcp", redisUrl)
},
}
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/ready", Ready)
router.HandleFunc("/secrets", CreateSecret).Methods("POST")
router.HandleFunc("/secrets/{secretID}", ReadSecret).Methods("POST")
if err := http.ListenAndServe(":9090", router); err != nil {
log.Fatalf("%+v", err)
}
}
func getEnv(key, defaultValue string) string {
value := os.Getenv(key)
if value == "" {
return defaultValue
}
return value
}