本文整理汇总了Golang中github.com/tsuru/tsuru/cmd.GetURL函数的典型用法代码示例。如果您正苦于以下问题:Golang GetURL函数的具体用法?Golang GetURL怎么用?Golang GetURL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetURL函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (c *templateList) Run(context *cmd.Context, client *cmd.Client) error {
url, err := cmd.GetURL("/iaas/templates")
if err != nil {
return err
}
request, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
response, err := client.Do(request)
if err != nil {
return err
}
var templates []iaas.Template
err = json.NewDecoder(response.Body).Decode(&templates)
if err != nil {
return err
}
table := cmd.NewTable()
table.Headers = cmd.Row([]string{"Name", "IaaS", "Params"})
table.LineSeparator = true
for _, template := range templates {
var params []string
for _, data := range template.Data {
params = append(params, fmt.Sprintf("%s=%s", data.Name, data.Value))
}
sort.Strings(params)
table.AddRow(cmd.Row([]string{template.Name, template.IaaSName, strings.Join(params, "\n")}))
}
table.Sort()
context.Stdout.Write(table.Bytes())
return nil
}
示例2: Run
func (c *InfoCmd) Run(context *cmd.Context, client *cmd.Client) error {
url, err := cmd.GetURL("/docker/bs")
if err != nil {
return err
}
request, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
response, err := client.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
var conf provision.ScopedConfig
err = json.NewDecoder(response.Body).Decode(&conf)
if err != nil {
return err
}
fmt.Fprintf(context.Stdout, "Image: %s\n\nEnvironment Variables [Default]:\n", conf.Extra["image"])
t := cmd.Table{Headers: cmd.Row([]string{"Name", "Value"})}
for _, envVar := range conf.Envs {
t.AddRow(cmd.Row([]string{envVar.Name, fmt.Sprintf("%v", envVar.Value)}))
}
context.Stdout.Write(t.Bytes())
for _, pool := range conf.Pools {
t := cmd.Table{Headers: cmd.Row([]string{"Name", "Value"})}
fmt.Fprintf(context.Stdout, "\nEnvironment Variables [%s]:\n", pool.Name)
for _, envVar := range pool.Envs {
t.AddRow(cmd.Row([]string{envVar.Name, fmt.Sprintf("%v", envVar.Value)}))
}
context.Stdout.Write(t.Bytes())
}
return nil
}
示例3: Run
func (c *autoScaleSetRuleCmd) Run(context *cmd.Context, client *cmd.Client) error {
if (c.enable && c.disable) || (!c.enable && !c.disable) {
return errors.New("either --disable or --enable must be set")
}
rule := autoScaleRule{
MetadataFilter: c.filterValue,
MaxContainerCount: c.maxContainerCount,
MaxMemoryRatio: float32(c.maxMemoryRatio),
ScaleDownRatio: float32(c.scaleDownRatio),
PreventRebalance: c.noRebalanceOnScale,
Enabled: c.enable,
}
val, err := form.EncodeToValues(rule)
if err != nil {
return err
}
body := strings.NewReader(val.Encode())
u, err := cmd.GetURL("/docker/autoscale/rules")
if err != nil {
return err
}
req, err := http.NewRequest("POST", u, body)
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
_, err = client.Do(req)
if err != nil {
return err
}
fmt.Fprintln(context.Stdout, "Rule successfully defined.")
return nil
}
示例4: BuildPlansTable
func (c serviceInfo) BuildPlansTable(serviceName string, ctx *cmd.Context, client *cmd.Client) error {
ctx.Stdout.Write([]byte("\nPlans\n"))
url, err := cmd.GetURL(fmt.Sprintf("/services/%s/plans", serviceName))
if err != nil {
return err
}
request, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
resp, err := client.Do(request)
if err != nil {
return err
}
defer resp.Body.Close()
result, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
var plans []map[string]string
err = json.Unmarshal(result, &plans)
if err != nil {
return err
}
if len(plans) > 0 {
table := cmd.NewTable()
for _, plan := range plans {
data := []string{plan["Name"], plan["Description"]}
table.AddRow(cmd.Row(data))
}
table.Headers = cmd.Row([]string{"Name", "Description"})
ctx.Stdout.Write(table.Bytes())
}
return nil
}
示例5: Run
func (c *serviceAdd) Run(ctx *cmd.Context, client *cmd.Client) error {
serviceName, instanceName := ctx.Args[0], ctx.Args[1]
var plan string
if len(ctx.Args) > 2 {
plan = ctx.Args[2]
}
var b bytes.Buffer
params := map[string]string{
"name": instanceName,
"service_name": serviceName,
"plan": plan,
"owner": c.teamOwner,
}
err := json.NewEncoder(&b).Encode(params)
if err != nil {
return err
}
url, err := cmd.GetURL("/services/instances")
if err != nil {
return err
}
request, err := http.NewRequest("POST", url, &b)
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/json")
_, err = client.Do(request)
if err != nil {
return err
}
fmt.Fprint(ctx.Stdout, "Service successfully added.\n")
return nil
}
示例6: Run
func (su *ServiceUnbind) Run(ctx *cmd.Context, client *cmd.Client) error {
appName, err := su.Guess()
if err != nil {
return err
}
instanceName := ctx.Args[0]
url, err := cmd.GetURL("/services/instances/" + instanceName + "/" + appName)
if err != nil {
return err
}
request, err := http.NewRequest("DELETE", url, nil)
if err != nil {
return err
}
_, err = client.Do(request)
if err != nil {
return err
}
msg := fmt.Sprintf("Instance %q is not bound to the app %q anymore.\n", instanceName, appName)
n, err := fmt.Fprint(ctx.Stdout, msg)
if err != nil {
return err
}
if n != len(msg) {
return errors.New("Failed to write to standard output.\n")
}
return nil
}
示例7: Run
func (c *appStart) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
appName, err := c.Guess()
if err != nil {
return err
}
url, err := cmd.GetURL(fmt.Sprintf("/apps/%s/start?process=%s", appName, c.process))
if err != nil {
return err
}
request, err := http.NewRequest("POST", url, nil)
if err != nil {
return err
}
response, err := client.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
_, err = io.Copy(context.Stdout, response.Body)
if err != nil {
return err
}
return nil
}
示例8: Run
func (c *appRun) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
appName, err := c.Guess()
if err != nil {
return err
}
url, err := cmd.GetURL(fmt.Sprintf("/apps/%s/run?once=%t", appName, c.once))
if err != nil {
return err
}
b := strings.NewReader(strings.Join(context.Args, " "))
request, err := http.NewRequest("POST", url, b)
if err != nil {
return err
}
r, err := client.Do(request)
if err != nil {
return err
}
defer r.Body.Close()
w := tsuruIo.NewStreamWriter(context.Stdout, nil)
for n := int64(1); n > 0 && err == nil; n, err = io.Copy(w, r.Body) {
}
if err != nil {
return err
}
unparsed := w.Remaining()
if len(unparsed) > 0 {
return fmt.Errorf("unparsed message error: %s", string(unparsed))
}
return nil
}
示例9: Run
func (c *autoScaleSetRuleCmd) Run(context *cmd.Context, client *cmd.Client) error {
rule := autoScaleRule{
MetadataFilter: c.filterValue,
MaxContainerCount: c.maxContainerCount,
MaxMemoryRatio: float32(c.maxMemoryRatio),
ScaleDownRatio: float32(c.scaleDownRatio),
PreventRebalance: !c.rebalanceOnScale,
Enabled: c.enabled,
}
data, err := json.Marshal(rule)
if err != nil {
return err
}
body := bytes.NewBuffer(data)
url, err := cmd.GetURL("/docker/autoscale/rules")
if err != nil {
return err
}
req, err := http.NewRequest("POST", url, body)
if err != nil {
return err
}
_, err = client.Do(req)
if err != nil {
return err
}
fmt.Fprintln(context.Stdout, "Rule successfully defined.")
return nil
}
示例10: addCName
func addCName(v []string, g cmd.GuessingCommand, client *cmd.Client) error {
appName, err := g.Guess()
if err != nil {
return err
}
url, err := cmd.GetURL(fmt.Sprintf("/apps/%s/cname", appName))
if err != nil {
return err
}
cnames := make(map[string][]string)
cnames["cname"] = v
c, err := json.Marshal(cnames)
if err != nil {
return err
}
body := bytes.NewReader(c)
request, err := http.NewRequest("POST", url, body)
if err != nil {
return err
}
_, err = client.Do(request)
if err != nil {
return err
}
return nil
}
示例11: Run
func (c *ListHealingHistoryCmd) Run(ctx *cmd.Context, client *cmd.Client) error {
var filter string
if c.nodeOnly && !c.containerOnly {
filter = "node"
}
if c.containerOnly && !c.nodeOnly {
filter = "container"
}
url, err := cmd.GetURL(fmt.Sprintf("/docker/healing?filter=%s", filter))
if err != nil {
return err
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
var history []HealingEvent
err = json.NewDecoder(resp.Body).Decode(&history)
if err != nil {
return err
}
if filter != "" {
renderHistoryTable(history, filter, ctx)
} else {
renderHistoryTable(history, "node", ctx)
renderHistoryTable(history, "container", ctx)
}
return nil
}
示例12: Run
func (c *rebalanceContainersCmd) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
if !c.dry && !c.Confirm(context, "Are you sure you want to rebalance containers?") {
return nil
}
url, err := cmd.GetURL("/docker/containers/rebalance")
if err != nil {
return err
}
params := map[string]interface{}{
"dry": fmt.Sprintf("%t", c.dry),
}
if len(c.metadataFilter) > 0 {
params["metadataFilter"] = c.metadataFilter
}
if len(c.appFilter) > 0 {
params["appFilter"] = c.appFilter
}
b, err := json.Marshal(params)
if err != nil {
return err
}
buffer := bytes.NewBuffer(b)
request, err := http.NewRequest("POST", url, buffer)
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/json")
response, err := client.Do(request)
if err != nil {
return err
}
return cmd.StreamJSONResponse(context.Stdout, response)
}
示例13: Run
func (c *moveContainerCmd) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
url, err := cmd.GetURL(fmt.Sprintf("/docker/container/%s/move", context.Args[0]))
if err != nil {
return err
}
params := map[string]string{
"to": context.Args[1],
}
b, err := json.Marshal(params)
if err != nil {
return err
}
buffer := bytes.NewBuffer(b)
request, err := http.NewRequest("POST", url, buffer)
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/json")
response, err := client.Do(request)
if err != nil {
return err
}
w := tsuruIo.NewStreamWriter(context.Stdout, nil)
for n := int64(1); n > 0 && err == nil; n, err = io.Copy(w, response.Body) {
}
if err != nil {
return err
}
unparsed := w.Remaining()
if len(unparsed) > 0 {
return fmt.Errorf("unparsed message error: %s", string(unparsed))
}
return nil
}
示例14: Run
func (c *unitAdd) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
appName, err := c.Guess()
if err != nil {
return err
}
u, err := cmd.GetURL(fmt.Sprintf("/apps/%s/units", appName))
if err != nil {
return err
}
val := url.Values{}
val.Add("units", context.Args[0])
val.Add("process", c.process)
request, err := http.NewRequest("PUT", u, bytes.NewBufferString(val.Encode()))
if err != nil {
return err
}
request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
response, err := client.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
return cmd.StreamJSONResponse(context.Stdout, response)
}