Ejemplo n.º 1
0
func vhostDelCommand(ctx *cli.Context) {
	workdir := ctx.GlobalString("workdir")
	if workdir == "" {
		fmt.Println("unknown working directory, please use -w to provide.")
		os.Exit(1)
	}

	// directory
	directory, err := filepath.Abs(workdir)
	if err != nil {
		fmt.Println("workdir:", err)
		return
	}

	configs, err := app.LoadCONFIG(path.Join(directory, "h2forward.conf"))
	if err != nil {
		fmt.Println("load configure failed:", err)
		return
	}

	addr := ctx.GlobalString("api")

	configs.SetSection("forward")
	AppID := configs.StringDefault("appid", "")
	Secret := configs.StringDefault("secret", "")

	client := api.NewClient(addr)
	auth := api.NewAdminAuth(AppID, Secret)

	args := ctx.Args()
	if len(args) == 0 {
		fmt.Println("command args: <hostname1> <hostname2> ...")
		return
	}

	for _, host := range args {
		if err := client.DelHost(nil, auth, host); err != nil {
			fmt.Println("det host failed:", err)
			return
		}
		fmt.Printf("det host (%s) ok.\n", host)
	}
	return
}
Ejemplo n.º 2
0
func vhostGetCommand(ctx *cli.Context) {
	workdir := ctx.GlobalString("workdir")
	if workdir == "" {
		fmt.Println("unknown working directory, please use -w to provide.")
		os.Exit(1)
	}

	// directory
	directory, err := filepath.Abs(workdir)
	if err != nil {
		fmt.Println("workdir:", err)
		return
	}

	configs, err := app.LoadCONFIG(path.Join(directory, "h2forward.conf"))
	if err != nil {
		fmt.Println("load configure failed:", err)
		return
	}

	addr := ctx.GlobalString("api")

	configs.SetSection("forward")
	AppID := configs.StringDefault("appid", "")
	Secret := configs.StringDefault("secret", "")

	client := api.NewClient(addr)
	auth := api.NewAdminAuth(AppID, Secret)

	hosts := ctx.Args()
	ret := map[string]interface{}{}
	if err := client.GetHost(nil, auth, hosts, &ret); err != nil {
		fmt.Println("get host failed:", err)
		return
	}

	b, _ := json.MarshalIndent(ret, "", " ")
	fmt.Println(string(b))
	return
}