-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
58 lines (46 loc) · 1009 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package configs
import (
"fmt"
"log"
"os"
)
type Server struct {
Port string
Host string
Ssl string
JWTSecret []byte
}
func (s *Server) Setup() {
s.Port = s.getPort()
s.Host = s.getHost()
s.Ssl = s.getHttp()
s.JWTSecret = s.getJWTSecret()
}
func (s *Server) GetFullPath() string {
return fmt.Sprintf("%v://%v:%v/", s.Ssl, s.Host, s.Port)
}
func (s *Server) getPort() string {
if port := os.Getenv("SERVER_PORT"); port != "" {
return port
}
return "8080"
}
func (s *Server) getHost() string {
if host := os.Getenv("SERVER_HOST"); host != "" {
return host
}
return "localhost"
}
func (s *Server) getHttp() string {
if http := os.Getenv("SERVER_SSL"); http != "" {
return "https"
}
return "http"
}
func (s *Server) getJWTSecret() []byte {
if jwtSecret := os.Getenv("JWT_SECRET_PASSWORD"); jwtSecret != "" {
return []byte(jwtSecret)
}
log.Fatalln("You must define 'JWT_SECRET_PASSWORD' environment variable for JWT authentication system")
return nil
}