/
consoleclient.go
92 lines (79 loc) · 2.45 KB
/
consoleclient.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// /////////////////////////////////////////////////////////////
// 'consoleclient.go' /
// /
// Copyright (c) 2018 Davsk℠. All Rights Reserved. /
// Use of this source code is governed by an ISC License (ISC) /
// that can be found in the LICENSE file. /
// /
// by David Skinner /
// on July 19, 2018 /
// for Davsk℠ Universe 4.0 project gbase /
// /
// /////////////////////////////////////////////////////////////
// Package consoleclient is a console client service
// for Universe 4.0 game.
//
// Overview
//
// consoleclient can be used alone in main to create
// a client application or it may be used with acctsrv
// and gameserver to create a standalone executable.
//
// Note that services must be started in sequence.
// acctsrv.MustStart()
// gameserver.MustStart()
// consoleclient.MustStart()
// nothing.Do()
package consoleclient
import (
"fmt"
"log"
"net/http"
"os"
"davsk.net/gbase/pkg/config"
"davsk.net/gbase/pkg/handler"
"davsk.net/gbase/pkg/must"
"github.com/goinggo/tracelog"
"gopkg.in/urfave/cli.v2"
)
// const Title for tracelog
const traceTitle = "consoleclient"
// Start starts the consoleclient service,
// returns nil when ready
// or returns error on failure.
func Start() error {
// const FunctionName for tracelog.
const traceFunctionName = "Start"
tracelog.Started(traceTitle, traceFunctionName)
// Load config.
cfg := config.NewConsoleClient()
tracelog.Info(traceTitle, traceFunctionName,
"ConsoleClient := %v", cfg)
// Completed successfully.
tracelog.Completed(traceTitle, traceFunctionName)
// handlers
// serve index (and anything else) as https.
mux := http.NewServeMux()
mux.HandleFunc("/", handler.Index)
// start
cfg.Start(mux)
// go console.Start()
app := new(cli.App)
app.Name = "boom"
app.Usage = "make an explosive entrance"
app.Action = func(c *cli.Context) error {
fmt.Println("boom! I say!")
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
// return status
return nil
}
// MustStart starts the consoleclient service, returns when ready
// and panics on failure.
func MustStart() {
must.Do(Start())
}