-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (44 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
package main
import (
"fmt"
"net/http"
"os"
flags "github.com/jessevdk/go-flags"
)
type Command struct {
Port int `short:"p" long:"port" description:"server port" default:"8080"`
CCV2Version string `long:"ccv2" description:"Cloud Controller V2 version number" default:"2.101.0"`
CCV3Version string `long:"ccv3" description:"Cloud Controller V3 version number" default:"3.36.0"`
UAAVersion string `long:"uaa" description:"UAA version number" default:"4.8.3"`
DisableRouting bool `long:"disable-routing" description:"Hide 'routing' from the root response"`
DisableV3 bool `long:"disable-ccv3" description:"return a 404 from the root response"`
DisableNetworkPolicyV0 bool `long:"disable-network-policy-v0" description:"Hide 'network_policy_v0' from the root response"`
DisableNetworkPolicyV1 bool `long:"disable-network-policy-v1" description:"Hide 'network_policy_v1' from the root response"`
serverURL string
}
func (opt *Command) Execute(args []string) error {
opt.serverURL = fmt.Sprintf("http://localhost:%d", opt.Port)
fmt.Println("API URL:", opt.serverURL)
http.HandleFunc("/login", opt.Login)
http.HandleFunc("/v2/info", opt.V2Info)
if opt.DisableV3 {
http.HandleFunc("/", opt.NotFound)
} else {
http.HandleFunc("/", opt.Root)
http.HandleFunc("/v3", opt.V3)
}
return http.ListenAndServe(fmt.Sprintf(":%d", opt.Port), nil)
}
func main() {
cmd := new(Command)
parser := flags.NewParser(cmd, flags.Default)
args, err := parser.Parse()
if err != nil {
os.Exit(1)
}
err = cmd.Execute(args)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}