forked from scribble-rs/scribble.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (35 loc) · 1.03 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
package main
import (
"flag"
"log"
"math/rand"
"os"
"strconv"
"time"
"github.com/scribble-rs/scribble.rs/communication"
)
func main() {
portHTTPFlag := flag.Int("portHTTP", -1, "defines the port to be used for http mode")
flag.Parse()
var portHTTP int
if *portHTTPFlag != -1 {
portHTTP = *portHTTPFlag
log.Printf("Listening on port %d sourced from portHTTP flag.\n", portHTTP)
} else {
//Support for heroku, as heroku expects applications to use a specific port.
envPort, _ := os.LookupEnv("PORT")
parsed, parseError := strconv.ParseInt(envPort, 10, 16)
if parseError == nil {
portHTTP = int(parsed)
log.Printf("Listening on port %d sourced from PORT environment variable\n", portHTTP)
} else {
portHTTP = 8080
log.Printf("Listening on default port %d\n", portHTTP)
}
}
//Setting the seed in order for the petnames to be random.
rand.Seed(time.Now().UnixNano())
log.Println("Started.")
//If this ever fails, it will return and print a fatal logger message
log.Fatal(communication.Serve(portHTTP))
}