Golang cf-errors.NewErrorWithMessage类(方法)实例源码

下面列出了Golang cf-errors.NewErrorWithMessage 类(方法)源码代码实例,从而了解它的用法。

作者:knollear    项目:cl   
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
}

作者:knollear    项目:cl   
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
}

作者:knollear    项目:cl   
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
}

作者:knollear    项目:cl   
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
}

作者:knollear    项目:cl   
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())
}

作者:knollear    项目:cl   
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
}

作者:jibin-tom    项目:cl   
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
}

作者:knollear    项目:cl   
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
}

作者:jibin-tom    项目:cl   
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
}

作者:knollear    项目:cl   
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
}

作者:jibin-tom    项目:cl   
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
}

作者:knollear    项目:cl   
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))
}

作者:knollear    项目:cl   
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
}

作者:knollear    项目:cl   
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
}

作者:knollear    项目:cl   
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
}

作者:knollear    项目:cl   
func (repo *FakeRouteRepository) CreateInSpace(host, domainGuid, spaceGuid string) (createdRoute models.Route, apiErr errors.Error) {
	repo.CreateInSpaceHost = host
	repo.CreateInSpaceDomainGuid = domainGuid
	repo.CreateInSpaceSpaceGuid = spaceGuid

	if repo.CreateInSpaceErr {
		apiErr = errors.NewErrorWithMessage("Error")
	} else {
		createdRoute = repo.CreateInSpaceCreatedRoute
	}

	return
}

作者:knollear    项目:cl   
func (repo *FakeDomainRepository) FindByName(name string) (domain models.DomainFields, apiErr errors.Error) {
	repo.FindByNameName = name
	domain = repo.FindByNameDomain

	if repo.FindByNameNotFound {
		apiErr = errors.NewModelNotFoundError("Domain", name)
	}
	if repo.FindByNameErr {
		apiErr = errors.NewErrorWithMessage("Error finding domain")
	}

	return
}

作者:knollear    项目:cl   
func (repo *FakeServiceBrokerRepo) ListServiceBrokers(callback func(broker models.ServiceBroker) bool) errors.Error {
	for _, broker := range repo.ServiceBrokers {
		if !callback(broker) {
			break
		}
	}

	if repo.ListErr {
		return errors.NewErrorWithMessage("Error finding service brokers")
	} else {
		return nil
	}
}

作者:jibin-tom    项目:cl   
func (repo RemoteEndpointRepository) GetLoggregatorEndpoint() (endpoint string, apiErr errors.Error) {
	if repo.config.LoggregatorEndpoint() == "" {
		if repo.config.ApiEndpoint() == "" {
			apiErr = errors.NewErrorWithMessage("Loggregator endpoint missing from config file")
		} else {
			endpoint = defaultLoggregatorEndpoint(repo.config.ApiEndpoint())
		}
	} else {
		endpoint = repo.config.LoggregatorEndpoint()
	}

	return
}

作者:knollear    项目:cl   
func (repo *FakeApplicationBitsRepository) UploadApp(appGuid, dir string, cb func(path string, zipSize, fileCount uint64)) (apiErr errors.Error) {
	repo.UploadedDir = dir
	repo.UploadedAppGuid = appGuid

	if repo.UploadAppErr {
		apiErr = errors.NewErrorWithMessage("Error uploading app")
		return
	}

	cb(repo.CallbackPath, repo.CallbackZipSize, repo.CallbackFileCount)

	return
}


问题


面经


文章

微信
公众号

扫码关注公众号