當前位置: 首頁>>代碼示例>>Golang>>正文


Golang CliConnection.GetService方法代碼示例

本文整理匯總了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")
}
開發者ID:cloudfoundry,項目名稱:v3-cli-plugin,代碼行數:46,代碼來源:bind_service.go


注:本文中的code/cloudfoundry/org/cli/plugin.CliConnection.GetService方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。