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


Golang net.NewApiResponseWithMessage函數代碼示例

本文整理匯總了Golang中cf/net.NewApiResponseWithMessage函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewApiResponseWithMessage函數的具體用法?Golang NewApiResponseWithMessage怎麽用?Golang NewApiResponseWithMessage使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewApiResponseWithMessage函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: createBuildpack

func (cmd CreateBuildpack) createBuildpack(buildpackName string, c *cli.Context) (buildpack cf.Buildpack, apiResponse net.ApiResponse) {
	position, err := strconv.Atoi(c.Args()[2])
	if err != nil {
		apiResponse = net.NewApiResponseWithMessage("Invalid position. %s", err.Error())
		return
	}

	enabled := c.Bool("enable")
	disabled := c.Bool("disable")
	if enabled && disabled {
		apiResponse = net.NewApiResponseWithMessage("Cannot specify both enabled and disabled.")
		return
	}

	var enableOption *bool = nil
	if enabled {
		enableOption = &enabled
	}
	if disabled {
		disabled = false
		enableOption = &disabled
	}

	buildpack, apiResponse = cmd.buildpackRepo.Create(buildpackName, &position, enableOption)

	return
}
開發者ID:nsnt,項目名稱:cli,代碼行數:27,代碼來源:create_buildpack.go

示例2: UploadApp

func (repo CloudControllerApplicationBitsRepository) UploadApp(appGuid string, appDir string, cb func(path string, zipSize, fileCount uint64)) (apiResponse net.ApiResponse) {
	fileutils.TempDir("apps", func(uploadDir string, err error) {
		if err != nil {
			apiResponse = net.NewApiResponseWithMessage(err.Error())
			return
		}

		var presentResourcesJson []byte
		repo.sourceDir(appDir, func(sourceDir string, sourceErr error) {
			if sourceErr != nil {
				err = sourceErr
				return
			}
			presentResourcesJson, err = repo.copyUploadableFiles(sourceDir, uploadDir)
		})

		if err != nil {
			apiResponse = net.NewApiResponseWithMessage("%s", err)
			return
		}

		fileutils.TempFile("uploads", func(zipFile *os.File, err error) {
			if err != nil {
				apiResponse = net.NewApiResponseWithMessage("%s", err.Error())
				return
			}

			err = repo.zipper.Zip(uploadDir, zipFile)
			if err != nil {
				apiResponse = net.NewApiResponseWithError("Error zipping application", err)
				return
			}

			stat, err := zipFile.Stat()
			if err != nil {
				apiResponse = net.NewApiResponseWithError("Error zipping application", err)
				return
			}
			cb(appDir, uint64(stat.Size()), cf.CountFiles(uploadDir))

			apiResponse = repo.uploadBits(appGuid, zipFile, presentResourcesJson)
			if apiResponse.IsNotSuccessful() {
				return
			}
		})
	})
	return
}
開發者ID:rodney-vin,項目名稱:cli,代碼行數:48,代碼來源:application_bits.go

示例3: ListRoutes

func (repo *FakeRouteRepository) ListRoutes(stop chan bool) (routesChan chan []cf.Route, statusChan chan net.ApiResponse) {
	routesChan = make(chan []cf.Route, 4)
	statusChan = make(chan net.ApiResponse, 1)

	if repo.ListErr {
		statusChan <- net.NewApiResponseWithMessage("Error finding all routes")
		close(routesChan)
		close(statusChan)
		return
	}

	go func() {
		routesCount := len(repo.Routes)
		for i := 0; i < routesCount; i += 2 {
			select {
			case <-stop:
				break
			default:
				if routesCount-i > 1 {
					routesChan <- repo.Routes[i : i+2]
				} else {
					routesChan <- repo.Routes[i:]
				}
			}
		}

		close(routesChan)
		close(statusChan)

		cf.WaitForClose(stop)
	}()

	return
}
開發者ID:nsnt,項目名稱:cli,代碼行數:34,代碼來源:fake_route_repo.go

示例4: ListServiceBrokers

func (repo *FakeServiceBrokerRepo) ListServiceBrokers(stop chan bool) (serviceBrokersChan chan []cf.ServiceBroker, statusChan chan net.ApiResponse) {
	serviceBrokersChan = make(chan []cf.ServiceBroker, 4)
	statusChan = make(chan net.ApiResponse, 1)

	if repo.ListErr {
		statusChan <- net.NewApiResponseWithMessage("Error finding all routes")
		close(serviceBrokersChan)
		close(statusChan)
		return
	}

	go func() {
		serviceBrokersCount := len(repo.ServiceBrokers)
		for i := 0; i < serviceBrokersCount; i += 2 {
			select {
			case <-stop:
				break
			default:
				if serviceBrokersCount-i > 1 {
					serviceBrokersChan <- repo.ServiceBrokers[i : i+2]
				} else {
					serviceBrokersChan <- repo.ServiceBrokers[i:]
				}
			}
		}

		close(serviceBrokersChan)
		close(statusChan)

		cf.WaitForClose(stop)
	}()

	return
}
開發者ID:nsnt,項目名稱:cli,代碼行數:34,代碼來源:fake_service_broker_repo.go

示例5: TestDeleteBuildpackDeleteError

func TestDeleteBuildpackDeleteError(t *testing.T) {
	ui := &testterm.FakeUI{Inputs: []string{"y"}}
	buildpack := cf.Buildpack{}
	buildpack.Name = "my-buildpack"
	buildpack.Guid = "my-buildpack-guid"
	buildpackRepo := &testapi.FakeBuildpackRepository{
		FindByNameBuildpack: buildpack,
		DeleteApiResponse:   net.NewApiResponseWithMessage("failed badly"),
	}

	cmd := NewDeleteBuildpack(ui, buildpackRepo)

	ctxt := testcmd.NewContext("delete-buildpack", []string{"my-buildpack"})
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}

	testcmd.RunCommand(cmd, ctxt, reqFactory)

	assert.Equal(t, buildpackRepo.DeleteBuildpackGuid, "my-buildpack-guid")

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting buildpack", "my-buildpack"},
		{"FAILED"},
		{"my-buildpack"},
		{"failed badly"},
	})
}
開發者ID:nsnt,項目名稱:cli,代碼行數:26,代碼來源:delete_buildpack_test.go

示例6: uploadBits

func (repo CloudControllerBuildpackBitsRepository) uploadBits(buildpack cf.Buildpack, zipFile *os.File) (apiResponse net.ApiResponse) {
	url := fmt.Sprintf("%s/v2/buildpacks/%s/bits", repo.config.Target, buildpack.Guid)

	fileutils.TempFile("requests", func(requestFile *os.File, err error) {
		if err != nil {
			apiResponse = net.NewApiResponseWithMessage(err.Error())
			return
		}

		boundary, err := repo.writeUploadBody(zipFile, requestFile)
		if err != nil {
			apiResponse = net.NewApiResponseWithError("Error creating upload", err)
			return
		}

		request, apiResponse := repo.gateway.NewRequest("PUT", url, repo.config.AccessToken, requestFile)
		contentType := fmt.Sprintf("multipart/form-data; boundary=%s", boundary)
		request.HttpReq.Header.Set("Content-Type", contentType)
		if apiResponse.IsNotSuccessful() {
			return
		}

		apiResponse = repo.gateway.PerformRequest(request)
	})

	return
}
開發者ID:pmuellr,項目名稱:cli,代碼行數:27,代碼來源:buildpack_bits.go

示例7: DeleteService

func (repo CloudControllerServiceRepository) DeleteService(instance cf.ServiceInstance) (apiResponse net.ApiResponse) {
	if len(instance.ServiceBindings) > 0 {
		return net.NewApiResponseWithMessage("Cannot delete service instance, apps are still bound to it")
	}
	path := fmt.Sprintf("%s/v2/service_instances/%s", repo.config.Target, instance.Guid)
	return repo.gateway.DeleteResource(path, repo.config.AccessToken)
}
開發者ID:pmuellr,項目名稱:cli,代碼行數:7,代碼來源:services.go

示例8: doUpdateEndpoint

func (repo RemoteEndpointRepository) doUpdateEndpoint(endpoint string) (apiResponse net.ApiResponse) {
	request, apiResponse := repo.gateway.NewRequest("GET", endpoint+"/v2/info", "", nil)
	if apiResponse.IsNotSuccessful() {
		return
	}

	type infoResponse struct {
		ApiVersion            string `json:"api_version"`
		AuthorizationEndpoint string `json:"authorization_endpoint"`
	}

	serverResponse := new(infoResponse)
	_, apiResponse = repo.gateway.PerformRequestForJSONResponse(request, &serverResponse)
	if apiResponse.IsNotSuccessful() {
		return
	}

	if endpoint != repo.config.Target {
		repo.configRepo.ClearSession()
	}

	repo.config.Target = endpoint
	repo.config.ApiVersion = serverResponse.ApiVersion
	repo.config.AuthorizationEndpoint = serverResponse.AuthorizationEndpoint

	err := repo.configRepo.Save()
	if err != nil {
		apiResponse = net.NewApiResponseWithMessage(err.Error())
	}
	return
}
開發者ID:jalateras,項目名稱:cli,代碼行數:31,代碼來源:endpoints.go

示例9: Start

func (repo *FakeApplicationRepository) Start(app cf.Application) (updatedApp cf.Application, apiResponse net.ApiResponse) {
	repo.StartAppToStart = app
	if repo.StartAppErr {
		apiResponse = net.NewApiResponseWithMessage("Error starting application")
	}
	updatedApp = repo.StartUpdatedApp
	return
}
開發者ID:jalateras,項目名稱:cli,代碼行數:8,代碼來源:fake_app_repo.go

示例10: FindAll

func (repo *FakeServiceBrokerRepo) FindAll() (serviceBrokers []cf.ServiceBroker, apiResponse net.ApiResponse) {
	if repo.FindAllErr {
		apiResponse = net.NewApiResponseWithMessage("Error finding all service brokers")
	}

	serviceBrokers = repo.FindAllServiceBrokers
	return
}
開發者ID:jalateras,項目名稱:cli,代碼行數:8,代碼來源:fake_service_broker_repo.go

示例11: UploadBuildpack

func (repo *FakeBuildpackBitsRepository) UploadBuildpack(buildpack cf.Buildpack, dir string) net.ApiResponse {
	if repo.UploadBuildpackErr {
		return net.NewApiResponseWithMessage("Invalid buildpack")
	}

	repo.UploadBuildpackPath = dir
	return repo.UploadBuildpackApiResponse
}
開發者ID:nsnt,項目名稱:cli,代碼行數:8,代碼來源:fake_buildpack_bits_repo.go

示例12: validateApplication

func validateApplication(app cf.Application) (apiResponse net.ApiResponse) {
	reg := regexp.MustCompile("^[0-9a-zA-Z\\-_]*$")
	if !reg.MatchString(app.Name) {
		apiResponse = net.NewApiResponseWithMessage("App name is invalid: name can only contain letters, numbers, underscores and hyphens")
	}

	return
}
開發者ID:jalateras,項目名稱:cli,代碼行數:8,代碼來源:applications.go

示例13: FindAll

func (repo *FakeRouteRepository) FindAll() (routes []cf.Route, apiResponse net.ApiResponse) {
	if repo.FindAllErr {
		apiResponse = net.NewApiResponseWithMessage("Error finding all routes")
	}

	routes = repo.FindAllRoutes
	return
}
開發者ID:jalateras,項目名稱:cli,代碼行數:8,代碼來源:fake_route_repo.go

示例14: cloudControllerEndpoint

func (repo RemoteEndpointRepository) cloudControllerEndpoint() (endpoint string, apiResponse net.ApiResponse) {
	if repo.config.Target == "" {
		apiResponse = net.NewApiResponseWithMessage("Endpoint missing from config file")
		return
	}

	endpoint = repo.config.Target
	return
}
開發者ID:jalateras,項目名稱:cli,代碼行數:9,代碼來源:endpoints.go

示例15: GetLoggregatorEndpoint

func (repo RemoteEndpointRepository) GetLoggregatorEndpoint() (endpoint string, apiResponse net.ApiResponse) {
	if repo.config.LoggregatorEndPoint == "" {
		apiResponse = net.NewApiResponseWithMessage("Loggregator endpoint missing from config file")
		return
	}

	endpoint = repo.config.LoggregatorEndPoint
	return
}
開發者ID:nsnt,項目名稱:cli,代碼行數:9,代碼來源:endpoints.go


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