-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.go
62 lines (54 loc) · 947 Bytes
/
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
59
60
61
62
package main
import (
"flag"
"os"
)
type Config struct {
roomCode string
domain string
scheme string
wsscheme string
}
var config *Config
func GetConfig() *Config {
if config == nil {
InitConfig()
}
return config
}
func InitConfig() {
_DOMAIN := "recv.live" // Your website
_SECURE := true // Whether the website uses https
isDev := os.Getenv("APP_ENV") == "dev"
if isDev {
roomCode := os.Getenv("ROOM")
port := os.Getenv("PORT")
if port == "" {
port = "8000"
}
config = &Config{
roomCode: roomCode,
domain: "localhost:" + port,
scheme: "http",
wsscheme: "ws",
}
} else {
flag.Parse()
roomCode := flag.Arg(0)
var scheme string
var wsscheme string
if _SECURE {
scheme = "https"
wsscheme = "wss"
} else {
scheme = "http"
wsscheme = "ws"
}
config = &Config{
roomCode: roomCode,
domain: _DOMAIN,
scheme: scheme,
wsscheme: wsscheme,
}
}
}