本文整理匯總了Golang中code/cloudfoundry/org/cli/plugin.CliConnection.GetService方法的典型用法代碼示例。如果您正苦於以下問題:Golang CliConnection.GetService方法的具體用法?Golang CliConnection.GetService怎麽用?Golang CliConnection.GetService使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/cloudfoundry/org/cli/plugin.CliConnection
的用法示例。
在下文中一共展示了CliConnection.GetService方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: BindService
func BindService(cliConnection plugin.CliConnection, args []string) {
customParameters := "{}"
fc := flags.New()
fc.NewStringFlag("parameters", "c", "Valid JSON object containing service-specific configuration parameters, provided either in-line or in a file. For a list of supported configuration parameters, see documentation for the particular service offering.")
fc.Parse(args...)
if fc.IsSet("c") {
customParameters = fc.String("c")
}
appName := fc.Args()[1]
serviceInstanceName := fc.Args()[2]
rawOutput, _ := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?names=%s", appName))
apps := V3AppsModel{}
output := strings.Join(rawOutput, "")
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
appGuid := apps.Apps[0].Guid
serviceInstance, err := cliConnection.GetService(serviceInstanceName)
FreakOut(err)
serviceInstanceGuid := serviceInstance.Guid
body := fmt.Sprintf(`{
"type": "app",
"relationships": {
"app": {"guid" : "%s"},
"service_instance": {"guid": "%s"}
},
"data": {
"parameters": %s
}
}`, appGuid, serviceInstanceGuid, customParameters)
if _, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/service_bindings"), "-X", "POST", "-d", body); err != nil {
fmt.Printf("Failed to bind app %s to service instance %s\n", appName, serviceInstanceName)
return
}
fmt.Println("OK")
}