本文整理匯總了Golang中github.com/mikebeyer/clc-cli/util.MaybeLoadConfig函數的典型用法代碼示例。如果您正苦於以下問題:Golang MaybeLoadConfig函數的具體用法?Golang MaybeLoadConfig怎麽用?Golang MaybeLoadConfig使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了MaybeLoadConfig函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: deletePool
func deletePool(client *clc.Client) cli.Command {
return cli.Command{
Name: "delete-pool",
Aliases: []string{"dp"},
Usage: "delete load balancer pool",
Flags: []cli.Flag{
cli.StringFlag{Name: "id", Usage: "load balancer id [required]"},
cli.StringFlag{Name: "location, l", Usage: "load balancer location [required]"},
cli.StringFlag{Name: "pool, p", Usage: "load balancer pool id [required]"},
},
Before: func(c *cli.Context) error {
if c.String("location") == "" || c.String("id") == "" || c.String("pool") == "" {
fmt.Printf("missing required flags to get pool. [use --help to show required flags]\n")
return fmt.Errorf("")
}
return nil
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
err = client.LB.DeletePool(c.String("location"), c.String("id"), c.String("pool"))
if err != nil {
fmt.Printf("failed to get %s\n", c.Args().First())
return
}
fmt.Printf("sucessfully deleted pool [%s] from lb [%s]\n", c.String("pool"), c.String("id"))
},
}
}
示例2: get
func get(client *clc.Client) cli.Command {
return cli.Command{
Name: "get",
Aliases: []string{"g"},
Usage: "get status",
Before: func(c *cli.Context) error {
if c.Args().First() == "" {
fmt.Println("usage: get [id]")
return errors.New("")
}
return nil
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
status, err := client.Status.Get(c.Args().First())
if err != nil {
fmt.Printf("failed to get status of %s", c.Args().First())
return
}
b, err := json.MarshalIndent(status, "", " ")
if err != nil {
fmt.Printf("%s", err)
return
}
fmt.Printf("%s\n", b)
},
}
}
示例3: delete
func delete(client *clc.Client) cli.Command {
return cli.Command{
Name: "delete",
Aliases: []string{"d"},
Usage: "delete alert policy",
Before: func(c *cli.Context) error {
if c.Args().First() == "" {
fmt.Println("usage: delete [policy]")
return errors.New("")
}
return nil
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
err = client.Alert.Delete(c.Args().First())
if err != nil {
fmt.Printf("failed to get %s", c.Args().First())
return
}
fmt.Printf("deleted policy %s\n", c.Args().First())
},
}
}
示例4: get
func get(client *clc.Client) cli.Command {
return cli.Command{
Name: "get",
Aliases: []string{"g"},
Usage: "get server details",
Before: func(c *cli.Context) error {
return util.CheckArgs(c)
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
server, err := client.Server.Get(c.Args().First())
if err != nil {
fmt.Printf("failed to get %s\n", c.Args().First())
return
}
b, err := json.MarshalIndent(server, "", " ")
if err != nil {
fmt.Printf("%s", err)
return
}
fmt.Printf("%s\n", b)
},
}
}
示例5: deleteIP
func deleteIP(client *clc.Client) cli.Command {
return cli.Command{
Name: "delete",
Aliases: []string{"d"},
Usage: "delete public ip",
Flags: []cli.Flag{
cli.StringFlag{Name: "name, n", Usage: "server name [required]"},
cli.StringFlag{Name: "ip", Usage: "ip [required]"},
},
Before: func(c *cli.Context) error {
return util.CheckStringFlag(c, "name", "ip")
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
resp, err := client.Server.DeletePublicIP(c.String("name"), c.String("ip"))
if err != nil {
fmt.Printf("err %s\n", err)
return
}
b, err := json.MarshalIndent(resp, "", " ")
if err != nil {
fmt.Printf("%s", err)
return
}
fmt.Printf("%s\n", b)
},
}
}
示例6: restore
func restore(client *clc.Client) cli.Command {
return cli.Command{
Name: "restore",
Aliases: []string{"r"},
Usage: "restore server",
Flags: []cli.Flag{
cli.StringFlag{Name: "name, n", Usage: "name of server to restore [required]"},
cli.StringFlag{Name: "group, g", Usage: "group for server to restore to [required]"},
},
Before: func(c *cli.Context) error {
return util.CheckStringFlag(c, "name", "group")
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
resp, err := client.Server.Restore(c.String("name"), c.String("group"))
if err != nil {
fmt.Printf("failed to restore %s", c.String("name"))
return
}
b, err := json.MarshalIndent(resp, "", " ")
if err != nil {
fmt.Printf("%s", err)
return
}
fmt.Printf("%s\n", b)
},
}
}
示例7: archive
func archive(client *clc.Client) cli.Command {
return cli.Command{
Name: "archive",
Aliases: []string{"a"},
Usage: "archive server",
Flags: []cli.Flag{
cli.StringSliceFlag{Name: "name, n", Usage: "name of servers to archive"},
},
Before: func(c *cli.Context) error {
return util.CheckStringSliceFlag(c, "name")
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
resp, err := client.Server.Archive(c.StringSlice("name")...)
if err != nil {
fmt.Printf("failed to archive %s", strings.Join(c.StringSlice("name"), ", "))
return
}
b, err := json.MarshalIndent(resp, "", " ")
if err != nil {
fmt.Printf("%s", err)
return
}
fmt.Printf("%s\n", b)
},
}
}
示例8: delete
func delete(client *clc.Client) cli.Command {
return cli.Command{
Name: "delete",
Aliases: []string{"d"},
Usage: "delete group details",
Before: func(c *cli.Context) error {
return util.CheckArgs(c)
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
resp, err := client.Group.Delete(c.Args().First())
if err != nil {
fmt.Printf("failed to delete %s", c.Args().First())
return
}
b, err := json.MarshalIndent(resp, "", " ")
if err != nil {
fmt.Printf("%s", err)
return
}
fmt.Printf("%s\n", b)
},
}
}
示例9: updatePool
func updatePool(client *clc.Client) cli.Command {
return cli.Command{
Name: "update-pool",
Aliases: []string{"up"},
Usage: "update load balancer pool",
Flags: []cli.Flag{
cli.StringFlag{Name: "id", Usage: "load balancer id [required]"},
cli.StringFlag{Name: "location, l", Usage: "load balancer location [required]"},
cli.StringFlag{Name: "pool, p", Usage: "load balancer pool id [required]"},
cli.BoolFlag{Name: "sticky", Usage: "use stick persistence"},
cli.BoolFlag{Name: "standard", Usage: "use standard persistence [default]"},
cli.BoolFlag{Name: "least-connection, lc", Usage: "use least-connection load balacing"},
cli.BoolFlag{Name: "round-robin, rr", Usage: "use round-robin load balacing [default]"},
},
Before: func(c *cli.Context) error {
if c.Bool("sticky") && c.Bool("standard") {
fmt.Println("only one of sticky and standard can be selected")
return fmt.Errorf("")
}
if c.Bool("least-connection") && c.Bool("round-robin") {
fmt.Println("only one of least-connection and round-robin can be selected")
return fmt.Errorf("")
}
if c.String("id") == "" || c.String("location") == "" || c.String("pool") == "" {
fmt.Println("missing required flags, --help for more details")
return fmt.Errorf("")
}
return nil
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
pool := lb.Pool{}
if c.Bool("sticky") {
pool.Persistence = lb.Sticky
} else {
pool.Persistence = lb.Standard
}
if c.Bool("least-connection") {
pool.Method = lb.LeastConn
} else {
pool.Method = lb.RoundRobin
}
err = client.LB.UpdatePool(c.String("location"), c.String("id"), c.String("pool"), pool)
if err != nil {
fmt.Printf("failed to update load balancer pool [%s] in %s\n", c.String("pool"), c.String("location"))
return
}
fmt.Printf("successfully updated pool [%s]\n", c.String("pool"))
},
}
}
示例10: create
func create(client *clc.Client) cli.Command {
return cli.Command{
Name: "create",
Aliases: []string{"c"},
Usage: "create server",
Description: "example: clc server create -n 'my cool server' -c 1 -m 1 -g [group id] -t standard --ubuntu-14",
Flags: append(createFlags(), templateFlags()...),
Before: func(c *cli.Context) error {
err := util.CheckStringFlag(c, "name", "cpu", "memory", "group")
if err == nil {
err = util.CheckForEitherBooleanFlag(c, "standard", "hyperscale")
}
return err
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
source, err := findTemplateInContext(c)
if err != nil {
return
}
server := server.Server{
Name: c.String("name"),
CPU: c.Int("cpu"),
MemoryGB: c.Int("memory"),
GroupID: c.String("group"),
SourceServerID: source,
Type: deriveServerType(c),
}
server.Password = c.String("password")
server.Description = c.String("description")
server.IPaddress = c.String("ip")
server.IsManagedOS = c.Bool("managed")
server.PrimaryDNS = c.String("primaryDNS")
server.SecondaryDNS = c.String("secondaryDNS")
server.NetworkID = c.String("network")
server.Storagetype = deriveStorageType(c)
resp, err := client.Server.Create(server)
if err != nil {
fmt.Printf("failed to create %s", server.Name)
return
}
b, err := json.MarshalIndent(resp, "", " ")
if err != nil {
fmt.Printf("%s", err)
return
}
fmt.Printf("%s\n", b)
},
}
}
示例11: createIP
func createIP(client *clc.Client) cli.Command {
return cli.Command{
Name: "add",
Aliases: []string{"a"},
Usage: "add public ip to server",
Flags: []cli.Flag{
cli.StringFlag{Name: "name, n", Usage: "server name [required]"},
cli.StringSliceFlag{Name: "tcp", Usage: "provide a port [8080] or a port range [8080:8082]"},
cli.StringSliceFlag{Name: "udp", Usage: "provide a port [8080] or a port range [8080:8082]"},
cli.StringSliceFlag{Name: "restriction, r", Usage: "provide an ip subnet to restrict to access the public ip [ex. 10.0.0.1/24 (must be cidr notation)]"},
},
Before: func(c *cli.Context) error {
err := util.CheckStringFlag(c, "name")
if err == nil {
err = util.CheckForAnyOfStringSliceFlag(c, "tcp", "udp")
}
return err
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
ports := make([]server.Port, 0)
tcps, err := parsePort("tcp", c.StringSlice("tcp"))
if err != nil {
fmt.Println(err.Error())
}
ports = append(ports, tcps...)
udps, err := parsePort("udp", c.StringSlice("udp"))
if err != nil {
fmt.Println(err.Error())
}
ports = append(ports, udps...)
restrictions := make([]server.SourceRestriction, 0)
for _, v := range c.StringSlice("restriction") {
restrictions = append(restrictions, server.SourceRestriction{CIDR: v})
}
ip := server.PublicIP{Ports: ports}
resp, err := client.Server.AddPublicIP(c.String("name"), ip)
if err != nil {
fmt.Printf("err %s\n", err)
return
}
b, err := json.MarshalIndent(resp, "", " ")
if err != nil {
fmt.Printf("%s", err)
return
}
fmt.Printf("%s\n", b)
},
}
}
示例12: getPool
func getPool(client *clc.Client) cli.Command {
return cli.Command{
Name: "get-pool",
Aliases: []string{"gp"},
Usage: "get load balancer pool details",
Flags: []cli.Flag{
cli.BoolFlag{Name: "all", Usage: "list all load balancers for location"},
cli.StringFlag{Name: "id", Usage: "load balancer id [required]"},
cli.StringFlag{Name: "location, l", Usage: "load balancer location [required]"},
cli.StringFlag{Name: "pool, p", Usage: "load balancer pool id"},
},
Before: func(c *cli.Context) error {
if c.String("location") == "" || c.String("id") == "" {
fmt.Printf("missing required flags to get pool. [use --help to show required flags]\n")
return fmt.Errorf("")
}
return nil
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
if c.Bool("all") || c.String("pool") == "" {
resp, err := client.LB.GetAllPools(c.String("location"), c.String("id"))
if err != nil {
fmt.Printf("failed to get %s\n", c.Args().First())
return
}
b, err := json.MarshalIndent(resp, "", " ")
if err != nil {
fmt.Printf("%s\n", err)
return
}
fmt.Printf("%s\n", b)
return
}
resp, err := client.LB.GetPool(c.String("location"), c.String("id"), c.String("pool"))
if err != nil {
fmt.Printf("failed to get %s\n", c.Args().First())
return
}
b, err := json.MarshalIndent(resp, "", " ")
if err != nil {
fmt.Printf("%s\n", err)
return
}
fmt.Printf("%s\n", b)
},
}
}
示例13: updateNode
func updateNode(client *clc.Client) cli.Command {
return cli.Command{
Name: "update-node",
Aliases: []string{"un"},
Usage: "update load balancer node details",
Flags: []cli.Flag{
cli.StringFlag{Name: "id", Usage: "load balancer id [required]"},
cli.StringFlag{Name: "location, l", Usage: "load balancer location [required]"},
cli.StringFlag{Name: "pool, p", Usage: "load balancer pool id [required]"},
cli.StringSliceFlag{Name: "host, h", Usage: "node hostname and port (ex. 10.10.10.10:8080)"},
},
Before: func(c *cli.Context) error {
if c.String("location") == "" || c.String("id") == "" || c.String("pool") == "" {
fmt.Printf("missing required flags to get pool. [use --help to show required flags]\n")
return fmt.Errorf("")
}
return nil
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
nodes := make([]lb.Node, len(c.StringSlice("host")))
for i, v := range c.StringSlice("host") {
split := strings.Split(v, ":")
port, err := strconv.Atoi(split[1])
if err != nil {
fmt.Printf("failed parsing %s", v)
return
}
node := lb.Node{
IPaddress: split[0],
PrivatePort: port,
}
nodes[i] = node
}
err = client.LB.UpdateNodes(c.String("location"), c.String("id"), c.String("pool"), nodes...)
if err != nil {
fmt.Printf("failed to update nodes\n")
return
}
fmt.Printf("nodes updates for pool %s\n", c.String("pool"))
},
}
}
示例14: get
func get(client *clc.Client) cli.Command {
return cli.Command{
Name: "get",
Aliases: []string{"g"},
Usage: "get aa policy",
Flags: []cli.Flag{
cli.BoolFlag{Name: "all", Usage: "retrieve all policies"},
cli.StringFlag{Name: "alias, a", Usage: "account alias"},
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
if c.Bool("all") || c.Args().First() == "" {
policies, err := client.AA.GetAll()
if err != nil {
fmt.Printf("unable to retrieve aa policies\n")
return
}
b, err := json.MarshalIndent(policies, "", " ")
if err != nil {
fmt.Printf("%s", err)
return
}
fmt.Printf("%s\n", b)
return
}
policy, err := client.AA.Get(c.Args().First())
if err != nil {
fmt.Printf("unable to retrieve aa policy: [%s]\n", c.Args().First())
return
}
b, err := json.MarshalIndent(policy, "", " ")
if err != nil {
fmt.Printf("%s", err)
return
}
fmt.Printf("%s\n", b)
},
}
}
示例15: sshServer
func sshServer(client *clc.Client) cli.Command {
return cli.Command{
Name: "ssh",
Aliases: []string{"s"},
Usage: "ssh to server",
Before: func(c *cli.Context) error {
return util.CheckArgs(c)
},
Action: func(c *cli.Context) {
client, err := util.MaybeLoadConfig(c, client)
if err != nil {
fmt.Println(err.Error())
return
}
server, err := client.Server.Get(c.Args().First())
if err != nil {
fmt.Printf("failed to shh to %s\n", c.Args().First())
return
}
creds, err := client.Server.GetCredentials(c.Args().First())
if err != nil {
fmt.Printf("failed to shh to %s\n", c.Args().First())
return
}
internal, err := getInternal(server)
if err != nil {
fmt.Printf("failed to shh to %s\n", c.Args().First())
return
}
if err := connect(internal, creds); err != nil {
fmt.Printf("failed to shh to %s\n", c.Args().First())
return
}
},
}
}