-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
141 lines (119 loc) · 4.31 KB
/
main.go
File metadata and controls
141 lines (119 loc) · 4.31 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Copyright (c) Mainflux
*
* Mainflux server is licensed under an Apache license, version 2.0.
* All rights not explicitly granted in the Apache license, version 2.0 are reserved.
* See the included LICENSE file for more details.
*/
package main
import (
"flag"
"fmt"
"github.com/fatih/color"
"github.com/nodesign/weio-cloud/api"
"github.com/nodesign/weio-cloud/config"
"os"
"runtime"
"strconv"
"strings"
)
var usageStr = `
Usage: mainflux [options]
Server Options:
-a, --addr <host> Bind to host address (default: 0.0.0.0)
-p, --port <port> Use port for clients (default: 4222)
-P, --pid <file> File to store PID
-c, --config <file> Configuration file
Logging Options:
-l, --log <file> File to redirect log output
-T, --logtime Timestamp log entries (default: true)
-D, --debug Enable debugging output
-V, --trace Trace the raw protocol
-DV Debug and trace
Common Options:
-h, --help Show this message
-v, --version Show version
`
// usage will print out the flag options for the server.
func usage() {
fmt.Printf("%s\n", usageStr)
os.Exit(0)
}
// PrintServerAndExit will print our version and exit.
func PrintServerAndExit() {
fmt.Printf("Mainflux version %s\n", Version)
os.Exit(0)
}
func main() {
// Server Options
opts := Options{}
var showVersion bool
var debugAndTrace bool
var configFile string
// Parse flags
flag.IntVar(&opts.Port, "port", 0, "Port to listen on.")
flag.IntVar(&opts.Port, "p", 0, "Port to listen on.")
flag.StringVar(&opts.Host, "host", "", "Network host to listen on.")
flag.StringVar(&opts.Host, "h", "", "Network host to listen on.")
flag.StringVar(&opts.Host, "net", "", "Network host to listen on.")
flag.BoolVar(&opts.Debug, "D", false, "Enable Debug logging.")
flag.BoolVar(&opts.Debug, "debug", false, "Enable Debug logging.")
flag.BoolVar(&opts.Trace, "V", false, "Enable Trace logging.")
flag.BoolVar(&opts.Trace, "trace", false, "Enable Trace logging.")
flag.BoolVar(&debugAndTrace, "DV", false, "Enable Debug and Trace logging.")
flag.BoolVar(&opts.Logtime, "T", true, "Timestamp log entries.")
flag.BoolVar(&opts.Logtime, "logtime", true, "Timestamp log entries.")
flag.StringVar(&opts.Username, "user", "", "Username required for connection.")
flag.StringVar(&opts.Password, "pass", "", "Password required for connection.")
flag.StringVar(&opts.Authorization, "auth", "", "Authorization token required for connection.")
flag.StringVar(&configFile, "c", "", "Configuration file.")
flag.StringVar(&configFile, "config", "", "Configuration file.")
flag.StringVar(&opts.PidFile, "P", "", "File to store process pid.")
flag.StringVar(&opts.PidFile, "pid", "", "File to store process pid.")
flag.StringVar(&opts.LogFile, "l", "", "File to store logging output.")
flag.StringVar(&opts.LogFile, "log", "", "File to store logging output.")
flag.BoolVar(&showVersion, "version", false, "Print version information.")
flag.BoolVar(&showVersion, "v", false, "Print version information.")
flag.Usage = usage
flag.Parse()
// Show version and exit
if showVersion {
PrintServerAndExit()
}
// One flag can set multiple options.
if debugAndTrace {
opts.Trace, opts.Debug = true, true
}
// Process args looking for non-flag options,
// 'version' and 'help' only for now
for _, arg := range flag.Args() {
switch strings.ToLower(arg) {
case "version":
PrintServerAndExit()
case "help":
usage()
}
}
// Parse config
var cfg config.Config
cfg.Parse()
// Serve HTTP
go api.HTTPServer(cfg)
// Print banner
color.Yellow(banner)
color.Yellow("Magic happens on port " + strconv.Itoa(cfg.HTTPPort))
/** Keep main() runnig */
runtime.Goexit()
}
var banner = `
8 8 8 8 8"""88 8""""8
8 8 8 eeee 8 8 8 8 " e eeeee e e eeeee
8e 8 8 8 8e 8 8 8e 8 8 88 8 8 8 8
88 8 8 8eee 88 8 8 88 8e 8 8 8e 8 8e 8
88 8 8 88 88 8 8 88 e 88 8 8 88 8 88 8
88ee8ee8 88ee 88 8eeee8 88eee8 88eee 8eee8 88ee8 88ee8
== WeIO goes high ==
Made with <3 by Drasko DRASKOVIC and Uros PETREVSKI
[w] http://weio.net
[t] @weionoet
`