-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
53 lines (47 loc) · 948 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
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"github.com/go-redis/cache/v8"
"github.com/go-redis/redis/v8"
"net/http"
"os"
)
func main() {
// Load settings:
// ---
port := os.Getenv("PORT")
if len(port) == 0 {
port = "3000"
}
addr := ":" + port
baseURL := os.Getenv("BASE_URL")
if len(baseURL) == 0 {
baseURL = fmt.Sprintf("http://localhost:%s", port)
}
redisURL := os.Getenv("REDIS_URL")
if len(redisURL) == 0 {
redisURL = "redis://:@localhost:6379/1"
}
// Bootstrap:
// ---
redisOptions, err := redis.ParseURL(redisURL)
if err != nil {
panic(err)
}
redisClient := redis.NewClient(redisOptions)
defer redisClient.Close()
redisCache := cache.New(&cache.Options{
Redis: redisClient,
})
server := &Server{
BaseURL: baseURL,
RedisCache: redisCache,
}
// Start web server:
// ---
fmt.Printf("Starting web server, listening on %s\n", addr)
err = http.ListenAndServe(addr, server)
if err != nil {
panic(err)
}
}