本文整理汇总了Golang中github.com/convox/cli/stdcli.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: cmdEnvGet
func cmdEnvGet(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) == 0 {
stdcli.Error(errors.New("No variable specified"))
return
}
if len(c.Args()) > 1 {
stdcli.Error(errors.New("Only 1 variable can be retrieved at a time"))
return
}
variable := c.Args()[0]
resp, err := fetchEnv(app)
if err != nil {
stdcli.Error(err)
return
}
var env map[string]string
json.Unmarshal(resp, &env)
fmt.Println(env[variable])
}
示例2: cmdEnvGetAll
func cmdEnvGetAll(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
resp, err := fetchEnv(app)
if err != nil {
stdcli.Error(err)
return
}
var env map[string]string
err = json.Unmarshal(resp, &env)
if err != nil {
stdcli.Error(err)
return
}
keys := []string{}
for key, _ := range env {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
fmt.Printf("%s=%s\n", key, env[key])
}
}
示例3: processList
func processList(app string) {
data, err := ConvoxGet(fmt.Sprintf("/apps/%s/processes", app))
if err != nil {
stdcli.Error(err)
return
}
var processes *Processes
err = json.Unmarshal(data, &processes)
if err != nil {
stdcli.Error(err)
return
}
longest := 7
for _, ps := range *processes {
if len(ps.Name) > longest {
longest = len(ps.Name)
}
}
t := stdcli.NewTable("ID", "PROCESS", "RELEASE", "MEM", "COMMAND")
for _, ps := range *processes {
t.AddRow(ps.Id, ps.Name, ps.Release, fmt.Sprintf("%d", ps.Memory), ps.Command)
}
t.Print()
}
示例4: processList
func processList(app string) {
data, err := ConvoxGet(fmt.Sprintf("/apps/%s/processes", app))
if err != nil {
stdcli.Error(err)
return
}
var processes *Processes
err = json.Unmarshal(data, &processes)
if err != nil {
stdcli.Error(err)
return
}
longest := 7
for _, ps := range *processes {
if len(ps.Name) > longest {
longest = len(ps.Name)
}
}
fmt.Printf(fmt.Sprintf("%%-12s %%-%ds %%-11s %%-5s %%s\n", longest), "ID", "PROCESS", "RELEASE", "MEM", "COMMAND")
for _, ps := range *processes {
fmt.Printf(fmt.Sprintf("%%-12s %%-%ds %%-11s %%-5d %%s\n", longest), ps.Id, ps.Name, ps.Release, ps.Memory, ps.Command)
}
}
示例5: cmdServiceInfo
func cmdServiceInfo(c *cli.Context) {
if len(c.Args()) != 1 {
stdcli.Usage(c, "info")
return
}
name := c.Args()[0]
data, err := ConvoxGet("/services/" + name)
if err != nil {
stdcli.Error(err)
return
}
var s *Service
err = json.Unmarshal(data, &s)
if err != nil {
stdcli.Error(err)
return
}
fmt.Printf("Name %s\n", s.Name)
fmt.Printf("Status %s\n", s.Status)
fmt.Printf("URL %s\n", fmt.Sprintf("%s://%s:%[email protected]%s:%s/%s", s.Tags["Service"], s.Outputs["EnvPostgresUsername"], s.Outputs["EnvPostgresPassword"], s.Outputs["Port5432TcpAddr"], s.Outputs["Port5432TcpPort"], s.Outputs["EnvPostgresDatabase"]))
}
示例6: cmdServices
func cmdServices(c *cli.Context) {
data, err := ConvoxGet("/services")
if err != nil {
stdcli.Error(err)
return
}
var services *Services
err = json.Unmarshal(data, &services)
if err != nil {
stdcli.Error(err)
return
}
longest := 7
for _, service := range *services {
if len(service.Name) > longest {
longest = len(service.Name)
}
}
fmt.Printf(fmt.Sprintf("%%-%ds TYPE\n", longest), "SERVICE")
for _, service := range *services {
fmt.Printf(fmt.Sprintf("%%-%ds %%s\n", longest), service.Name, service.Tags["Service"])
}
}
示例7: cmdServiceInfo
func cmdServiceInfo(c *cli.Context) {
if len(c.Args()) != 1 {
stdcli.Usage(c, "info")
return
}
name := c.Args()[0]
data, err := ConvoxGet("/services/" + name)
if err != nil {
stdcli.Error(err)
return
}
var s *Service
err = json.Unmarshal(data, &s)
if err != nil {
stdcli.Error(err)
return
}
fmt.Printf("Name %s\n", s.Name)
fmt.Printf("Status %s\n", s.Status)
fmt.Printf("URL %s\n", s.URL)
}
示例8: cmdEnvGet
func cmdEnvGet(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) == 1 {
variable := c.Args()[0]
resp, err := fetchEnv(app)
if err != nil {
stdcli.Error(err)
return
}
var env map[string]string
json.Unmarshal(resp, &env)
fmt.Println(env[variable])
} else {
fmt.Printf("You supplied %d arguments to convox env get, 1 is required\n", len(c.Args()))
}
}
示例9: cmdExec
func cmdExec(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) < 1 {
stdcli.Usage(c, "exec")
return
}
ps := c.Args()[0]
command := ""
if len(c.Args()) > 1 {
args := c.Args()[1:]
command = strings.Join(args, " ")
}
err = stdcli.Run("docker", "exec", "-it", fmt.Sprintf("%s-%s", app, ps), "sh", "-c", command)
if err != nil {
stdcli.Error(err)
return
}
}
示例10: cmdRun
func cmdRun(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) < 1 {
stdcli.Usage(c, "run")
return
}
ps := c.Args()[0]
command := ""
if len(c.Args()) > 1 {
args := c.Args()[1:]
command = strings.Join(args, " ")
}
v := url.Values{}
v.Set("command", command)
_, err = ConvoxPostForm(fmt.Sprintf("/apps/%s/processes/%s/run", app, ps), v)
if err != nil {
stdcli.Error(err)
return
}
fmt.Printf("Running %s `%s`\n", ps, command)
}
示例11: cmdEnvUnset
func cmdEnvUnset(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) == 1 {
variable := c.Args()[0]
path := fmt.Sprintf("/apps/%s/environment/%s", app, variable)
_, err = ConvoxDelete(path)
if err != nil {
stdcli.Error(err)
return
}
else {
fmt.Printf("You supplied %d arguments to convox env unset, 1 is required\n", len(c.Args()))
}
}
func fetchEnv(app string) ([]byte, error) {
path := fmt.Sprintf("/apps/%s/environment", app)
resp, err := ConvoxGet(path)
if err != nil {
return nil, err
}
return resp, nil
}
示例12: ConvoxPost
func ConvoxPost(path string, body string) ([]byte, error) {
client := convoxClient()
req, err := convoxRequest("POST", path, strings.NewReader(body))
if err != nil {
stdcli.Error(err)
return nil, err
}
res, err := client.Do(req)
if err != nil {
stdcli.Error(err)
return nil, err
}
defer res.Body.Close()
data, err := ioutil.ReadAll(res.Body)
if err != nil {
stdcli.Error(err)
return nil, err
}
if res.StatusCode/100 != 2 {
return nil, errors.New(strings.TrimSpace(string(data)))
}
return data, nil
}
示例13: cmdEnvUnset
func cmdEnvUnset(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) == 0 {
stdcli.Error(errors.New("No variable specified"))
return
}
if len(c.Args()) > 1 {
stdcli.Error(errors.New("Only 1 variable can be unset at a time"))
return
}
variable := c.Args()[0]
path := fmt.Sprintf("/apps/%s/environment/%s", app, variable)
_, err = ConvoxDelete(path)
if err != nil {
stdcli.Error(err)
return
}
}
示例14: cmdBuildsInfo
func cmdBuildsInfo(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) != 1 {
stdcli.Usage(c, "info")
return
}
build := c.Args()[0]
path := fmt.Sprintf("/apps/%s/builds/%s", app, build)
resp, err := ConvoxGet(path)
if err != nil {
stdcli.Error(err)
return
}
var b Build
err = json.Unmarshal(resp, &b)
if err != nil {
stdcli.Error(err)
return
}
fmt.Println(b.Logs)
}
示例15: cmdBuilds
func cmdBuilds(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
path := fmt.Sprintf("/apps/%s/builds", app)
resp, err := ConvoxGet(path)
if err != nil {
stdcli.Error(err)
return
}
var builds []Build
err = json.Unmarshal(resp, &builds)
if err != nil {
stdcli.Error(err)
return
}
fmt.Printf("%-12s %-12s %-9s %-22s %s\n", "ID", "RELEASE", "STATUS", "STARTED", "ENDED")
for _, build := range builds {
started := build.Started
ended := build.Ended
fmt.Printf("%-12s %-12s %-9s %-22s %s\n", build.Id, build.Release, build.Status, started.Format(time.RFC822Z), ended.Format(time.RFC822Z))
}
}