-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
58 lines (48 loc) · 1.17 KB
/
config.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
package pusher
import (
"bufio"
"net/http"
"os"
"time"
"github.com/FlowerWrong/pusher/env"
"github.com/gorilla/websocket"
"github.com/spf13/viper"
)
// AppEnv is app env
var AppEnv string
const (
// DEVELOPMENT env
DEVELOPMENT = "development"
// TEST env
TEST = "test"
// PRODUCTION env
PRODUCTION = "production"
)
const (
writeWait = 10 * time.Second // Time allowed to write a message to the peer.
maxMessageSize = 1024 // Maximum message size allowed from peer.
)
var (
pongTimeout time.Duration
activityTimeout time.Duration
readTimeout time.Duration
)
var upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { return true },
ReadBufferSize: maxMessageSize,
WriteBufferSize: maxMessageSize,
}
// Setup ...
func Setup(file string) error {
AppEnv = env.Get("APP_ENV", DEVELOPMENT)
f, err := os.Open(file)
if err != nil {
return err
}
viper.SetConfigType("yaml")
viper.ReadConfig(bufio.NewReader(f))
pongTimeout = time.Duration(viper.GetInt64("PONG_TIMEOUT")) * time.Second
activityTimeout = time.Duration(viper.GetInt64("ACTIVITY_TIMEOUT")) * time.Second
readTimeout = activityTimeout / 9 * 10
return nil
}