forked from stilleshan/dockerfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (62 loc) · 1.33 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
package main
import (
"fmt"
"net/http"
"os"
"github.com/giuem/ga-proxy/server"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "ga-proxy"
app.HideVersion = true
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "ip, i",
Value: "127.0.0.1",
Usage: "`IP` to listen",
EnvVar: "IP",
},
cli.StringFlag{
Name: "port, p",
Value: "9080",
Usage: "`port` to listen",
EnvVar: "PORT",
},
}
app.Action = func(c *cli.Context) error {
server.Run(c.String("ip"), c.String("port"))
return nil
}
app.Commands = []cli.Command{
cli.Command{
Name: "ping",
Flags: []cli.Flag{
cli.StringFlag{
Name: "ip, i",
Value: "127.0.0.1",
Usage: "server `IP`",
EnvVar: "IP",
},
cli.StringFlag{
Name: "port, p",
Value: "9080",
Usage: "server `port`",
EnvVar: "PORT",
},
},
Action: func(c *cli.Context) error {
resp, err := http.Get(fmt.Sprintf("http://%v:%v/ping", c.String("ip"), c.String("port")))
if err != nil {
return cli.NewExitError(err, 1)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return cli.NewExitError(fmt.Errorf("server returns non-200 status code"), 1)
}
return nil
},
},
}
app.Run(os.Args)
}