-
Notifications
You must be signed in to change notification settings - Fork 4
/
cli.go
44 lines (36 loc) · 1.05 KB
/
cli.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
package main
import (
"fmt"
"github.com/mgutz/minimist"
"os"
)
var port, health int
var domain, proto string
var version = "v2.0.0"
var usage = `
A super simple HTTP redirection server
-h, --help print this message
-v, --version print 301 version
-p, --port port 301 will listen on (default 8080)
-d, --domain domain requests will redirect to (default 127.0.0.1)
--proto protocol HTTP or HTTPS (default HTTP)
--health optional port on which to listen for a health check
Handy for load balancers that will only accept a "200"
response to keep 301 instance(s) in load.
`
func handleCLI() (proto, domain string, port, health int) {
args := minimist.Parse()
if args.MayBool(false, "help", "h", "?") {
fmt.Println(usage)
os.Exit(0)
}
if args.MayBool(false, "v", "version") {
fmt.Println(version)
os.Exit(0)
}
port = args.MayInt(8080, "port", "p")
health = args.AsInt("health")
domain = args.MayString("127.0.0.1", "domain", "d")
proto = args.MayString("http", "proto")
return proto, domain, port, health
}