-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.go
40 lines (31 loc) · 831 Bytes
/
server.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
package main
import (
"github.com/csimplestring/autoscale-k8s-rest-example/customer"
"github.com/go-redis/redis"
"github.com/labstack/echo"
"github.com/labstack/gommon/log"
"os"
"strconv"
"time"
)
func main() {
addr := os.Getenv("API_SERVER_ADDR")
redisAddr := os.Getenv("REDIS_ADDR")
redisDB, _ := strconv.Atoi(os.Getenv("REDIS_DB"))
redisCli := redis.NewClient(&redis.Options{
Addr: redisAddr,
DB: redisDB,
DialTimeout: time.Second,
})
s := newServer(redisCli)
s.Logger.Fatal(s.Start(addr))
}
func newServer(redisCli *redis.Client) *echo.Echo {
customerController := customer.NewController(
customer.NewRepository(redisCli))
e := echo.New()
e.Logger.SetLevel(log.INFO)
e.GET("/customer/:name", customerController.Get)
e.POST("/customer", customerController.Create)
return e
}