/
main.go
72 lines (58 loc) · 1.6 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Hexgame Server
//
package main
import (
"fmt"
"flag"
// "os"
"github.com/markllama/hexgame-server/service"
)
var opts struct {
debug bool
verbose bool
url string
port int
}
// ---------------------------------------------------------------------------
// Configuration and environment variables
// ---------------------------------------------------------------------------
// verbose: HEXGAME_VERBOSE
// debug: HEXGAME_DEBUG
// url: HEXGAME_URL
// port: HEXGAME_PORT
//
func init() {
flag.BoolVar(&opts.verbose, "verbose", false, "provide verbose output")
flag.BoolVar(&opts.debug, "debug", false, "provide internal debugging output")
flag.StringVar(&opts.url, "url", "http://localhost", "server URL")
flag.IntVar(&opts.port, "port", 3000, "server port")
}
// arguments take precedence. Set those first.
func process_arguments() {
fmt.Println("Processing arguments")
flag.Parse()
}
// Set from environment if not set in args
func process_environment() {
fmt.Println("Processing envronment")
}
// andy required value that has not been set and has a default gets set here
func process_defaults() {
fmt.Println("Processing defaults")
}
// ---------------------------------------------------------------------------
// MAIN
// ---------------------------------------------------------------------------
func main() {
fmt.Println("-- Start Program --");
process_arguments()
process_environment()
process_defaults()
if opts.debug {
fmt.Println("Options: ", opts)
}
game_service := service.NewServer()
game_service.Run(fmt.Sprintf(":%d", opts.port))
fmt.Println("-- End Program --");
}