本文整理匯總了Golang中cf/errors.NewErrorWithMessage函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewErrorWithMessage函數的具體用法?Golang NewErrorWithMessage怎麽用?Golang NewErrorWithMessage使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewErrorWithMessage函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createBuildpack
func (cmd CreateBuildpack) createBuildpack(buildpackName string, c *cli.Context) (buildpack models.Buildpack, apiErr errors.Error) {
position, err := strconv.Atoi(c.Args()[2])
if err != nil {
apiErr = errors.NewErrorWithMessage("Invalid position. %s", err.Error())
return
}
enabled := c.Bool("enable")
disabled := c.Bool("disable")
if enabled && disabled {
apiErr = errors.NewErrorWithMessage("Cannot specify both enabled and disabled.")
return
}
var enableOption *bool = nil
if enabled {
enableOption = &enabled
}
if disabled {
disabled = false
enableOption = &disabled
}
buildpack, apiErr = cmd.buildpackRepo.Create(buildpackName, &position, enableOption, nil)
return
}
示例2: UploadApp
func (repo CloudControllerApplicationBitsRepository) UploadApp(appGuid string, appDir string, cb func(path string, zipSize, fileCount uint64)) (apiErr errors.Error) {
fileutils.TempDir("apps", func(uploadDir string, err error) {
if err != nil {
apiErr = errors.NewErrorWithMessage(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 {
apiErr = errors.NewErrorWithMessage("%s", err)
return
}
fileutils.TempFile("uploads", func(zipFile *os.File, err error) {
if err != nil {
apiErr = errors.NewErrorWithMessage("%s", err.Error())
return
}
err = repo.zipper.Zip(uploadDir, zipFile)
if err != nil {
apiErr = errors.NewErrorWithError("Error zipping application", err)
return
}
stat, err := zipFile.Stat()
if err != nil {
apiErr = errors.NewErrorWithError("Error zipping application", err)
return
}
cb(appDir, uint64(stat.Size()), app_files.CountFiles(uploadDir))
apiErr = repo.uploadBits(appGuid, zipFile, presentResourcesJson)
if apiErr != nil {
return
}
})
})
return
}
示例3: getAuthEndpoint
func (repo CloudControllerUserRepository) getAuthEndpoint() (string, errors.Error) {
uaaEndpoint := repo.config.UaaEndpoint()
if uaaEndpoint == "" {
return "", errors.NewErrorWithMessage("UAA endpoint missing from config file")
}
return uaaEndpoint, nil
}
示例4: waitForJob
func (gateway Gateway) waitForJob(jobUrl, accessToken string, timeout time.Duration) (apiErr errors.Error) {
startTime := time.Now()
for true {
if time.Since(startTime) > timeout {
apiErr = errors.NewErrorWithMessage("Error: timed out waiting for async job '%s' to finish", jobUrl)
return
}
var request *Request
request, apiErr = gateway.NewRequest("GET", jobUrl, accessToken, nil)
response := &JobResponse{}
_, apiErr = gateway.PerformRequestForJSONResponse(request, response)
if apiErr != nil {
return
}
switch response.Entity.Status {
case JOB_FINISHED:
return
case JOB_FAILED:
apiErr = errors.NewError("Job failed", JOB_FAILED)
return
}
accessToken = request.HttpReq.Header.Get("Authorization")
time.Sleep(gateway.PollingThrottle)
}
return
}
示例5: DeleteService
func (repo CloudControllerServiceRepository) DeleteService(instance models.ServiceInstance) (apiErr errors.Error) {
if len(instance.ServiceBindings) > 0 {
return errors.NewErrorWithMessage("Cannot delete service instance, apps are still bound to it")
}
path := fmt.Sprintf("%s/v2/service_instances/%s", repo.config.ApiEndpoint(), instance.Guid)
return repo.gateway.DeleteResource(path, repo.config.AccessToken())
}
示例6: UploadBuildpack
func (repo *FakeBuildpackBitsRepository) UploadBuildpack(buildpack models.Buildpack, dir string) errors.Error {
if repo.UploadBuildpackErr {
return errors.NewErrorWithMessage("Invalid buildpack")
}
repo.UploadBuildpackPath = dir
return repo.UploadBuildpackApiResponse
}
示例7: GetCloudControllerEndpoint
func (repo RemoteEndpointRepository) GetCloudControllerEndpoint() (endpoint string, apiErr errors.Error) {
if repo.config.ApiEndpoint() == "" {
apiErr = errors.NewErrorWithMessage("Target endpoint missing from config file")
return
}
endpoint = repo.config.ApiEndpoint()
return
}
示例8: Update
func (repo *FakeApplicationRepository) Update(appGuid string, params models.AppParams) (updatedApp models.Application, apiErr errors.Error) {
repo.UpdateAppGuid = appGuid
repo.UpdateParams = params
updatedApp = repo.UpdateAppResult
if repo.UpdateErr {
apiErr = errors.NewErrorWithMessage("Error updating app.")
}
return
}
示例9: GetUAAEndpoint
func (repo RemoteEndpointRepository) GetUAAEndpoint() (endpoint string, apiErr errors.Error) {
if repo.config.AuthorizationEndpoint() == "" {
apiErr = errors.NewErrorWithMessage("UAA endpoint missing from config file")
return
}
endpoint = strings.Replace(repo.config.AuthorizationEndpoint(), "login", "uaa", 1)
return
}
示例10: FindByHost
func (repo *FakeRouteRepository) FindByHost(host string) (route models.Route, apiErr errors.Error) {
repo.FindByHostHost = host
if repo.FindByHostErr {
apiErr = errors.NewErrorWithMessage("Route not found")
}
route = repo.FindByHostRoute
return
}
示例11: checkSpaceRole
func (repo CloudControllerUserRepository) checkSpaceRole(userGuid, spaceGuid, role string) (fullPath string, apiErr errors.Error) {
rolePath, found := spaceRoleToPathMap[role]
if !found {
apiErr = errors.NewErrorWithMessage("Invalid Role %s", role)
}
fullPath = fmt.Sprintf("%s/v2/spaces/%s/%s/%s", repo.config.ApiEndpoint(), spaceGuid, rolePath, userGuid)
return
}
示例12: UpdatePassword
func (repo CloudControllerPasswordRepository) UpdatePassword(old string, new string) errors.Error {
uaaEndpoint := repo.config.UaaEndpoint()
if uaaEndpoint == "" {
return errors.NewErrorWithMessage("UAA endpoint missing from config file")
}
url := fmt.Sprintf("%s/Users/%s/password", uaaEndpoint, repo.config.UserGuid())
body := fmt.Sprintf(`{"password":"%s","oldPassword":"%s"}`, new, old)
return repo.gateway.UpdateResource(url, repo.config.AccessToken(), strings.NewReader(body))
}
示例13: ListRoutes
func (repo *FakeRouteRepository) ListRoutes(cb func(models.Route) bool) (apiErr errors.Error) {
if repo.ListErr {
return errors.NewErrorWithMessage("WHOOPSIE")
}
for _, route := range repo.Routes {
if !cb(route) {
break
}
}
return
}
示例14: FindByName
func (repo *FakeQuotaRepository) FindByName(name string) (quota models.QuotaFields, apiErr errors.Error) {
repo.FindByNameName = name
quota = repo.FindByNameQuota
if repo.FindByNameNotFound {
apiErr = errors.NewModelNotFoundError("Org", name)
}
if repo.FindByNameErr {
apiErr = errors.NewErrorWithMessage("Error finding quota")
}
return
}
示例15: setOrganization
func (cmd Target) setOrganization(orgName string) error {
// setting an org necessarily invalidates any space you had previously targeted
cmd.config.SetOrganizationFields(models.OrganizationFields{})
cmd.config.SetSpaceFields(models.SpaceFields{})
org, apiErr := cmd.orgRepo.FindByName(orgName)
if apiErr != nil {
return errors.NewErrorWithMessage("Could not target org.\n%s", apiErr.Error())
}
cmd.config.SetOrganizationFields(org.OrganizationFields)
return nil
}