-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (41 loc) · 1.19 KB
/
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
package main
import (
"fmt"
"net/http"
"os"
"time"
"moxiechat/handler"
)
func main() {
address := handler.Config.Address
// If port env var is set, PaaS platform (Heroku) is being used
if port, ok := os.LookupEnv("PORT"); ok {
address = "0.0.0.0:" + port
}
// starting up the server
server := &http.Server{
Addr: address,
Handler: handler.Mux,
ReadTimeout: time.Duration(handler.Config.ReadTimeout * int64(time.Second)),
WriteTimeout: time.Duration(handler.Config.WriteTimeout * int64(time.Second)),
MaxHeaderBytes: 1 << 20,
}
fmt.Println("Moxiechat", version(), "started at", server.Addr)
if _, exist := os.LookupEnv("PORT"); exist {
// TLS is already enabled on Heroku PaaS platform
if err := server.ListenAndServe(); err != nil {
fmt.Println("Error starting server", err.Error())
}
} else {
if err := server.ListenAndServeTLS("gencert/cert.pem", "gencert/key.pem"); err != nil {
// If TLS fails e.g. because certs are missing on CI test env, we will fallback to regular HTTP
if err := server.ListenAndServe(); err != nil {
fmt.Println("Error starting server", err.Error())
}
}
}
}
// version
func version() string {
return "0.1"
}