本文整理匯總了Golang中cf/errors.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: readAllYAMLFiles
func (repo ManifestDiskRepository) readAllYAMLFiles(path string) (mergedMap generic.Map, err error) {
file, err := os.Open(filepath.Clean(path))
if err != nil {
return
}
defer file.Close()
mapp, err := parseManifest(file)
if err != nil {
return
}
if !mapp.Has("inherit") {
mergedMap = mapp
return
}
inheritedPath, ok := mapp.Get("inherit").(string)
if !ok {
err = errors.New("invalid inherit path in manifest")
return
}
if !filepath.IsAbs(inheritedPath) {
inheritedPath = filepath.Join(filepath.Dir(path), inheritedPath)
}
inheritedMap, err := repo.readAllYAMLFiles(inheritedPath)
if err != nil {
return
}
mergedMap = generic.DeepMerge(inheritedMap, mapp)
return
}
示例2: findDefaultDomain
func (cmd *Push) findDefaultDomain() (domain models.DomainFields, err error) {
foundIt := false
listDomainsCallback := func(aDomain models.DomainFields) bool {
if aDomain.Shared {
domain = aDomain
foundIt = true
}
return !foundIt
}
apiErr := cmd.domainRepo.ListSharedDomains(listDomainsCallback)
// FIXME: needs semantic API version
switch apiErr.(type) {
case errors.HttpNotFoundError:
apiErr = cmd.domainRepo.ListDomains(listDomainsCallback)
}
if !foundIt {
err = errors.New("Could not find a default domain")
return
}
return
}
示例3: waitForJob
func (gateway Gateway) waitForJob(jobUrl, accessToken string, timeout time.Duration) (err error) {
startTime := time.Now()
for true {
if time.Since(startTime) > timeout {
err = errors.NewWithFmt("Error: timed out waiting for async job '%s' to finish", jobUrl)
return
}
var request *Request
request, err = gateway.NewRequest("GET", jobUrl, accessToken, nil)
response := &JobResource{}
_, err = gateway.PerformRequestForJSONResponse(request, response)
if err != nil {
return
}
switch response.Entity.Status {
case JOB_FINISHED:
return
case JOB_FAILED:
err = errors.New(response.Entity.ErrorDetails.Description)
return
}
accessToken = request.HttpReq.Header.Get("Authorization")
time.Sleep(gateway.PollingThrottle)
}
return
}
示例4: GetRequirements
func (cmd PurgeServiceOffering) GetRequirements(reqFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 1 {
err = errors.New("incorrect usage")
cmd.ui.FailWithUsage(c, "purge-service-offering")
}
return
}
示例5: createBuildpack
func (cmd CreateBuildpack) createBuildpack(buildpackName string, c *cli.Context) (buildpack models.Buildpack, apiErr error) {
position, err := strconv.Atoi(c.Args()[2])
if err != nil {
apiErr = errors.NewWithFmt("Invalid position. %s", err.Error())
return
}
enabled := c.Bool("enable")
disabled := c.Bool("disable")
if enabled && disabled {
apiErr = errors.New("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
}
示例6: DeleteService
func (repo CloudControllerServiceRepository) DeleteService(instance models.ServiceInstance) (apiErr error) {
if len(instance.ServiceBindings) > 0 {
return errors.New("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)
}
示例7: getAppMaps
func (m Manifest) getAppMaps(data generic.Map) (apps []generic.Map, errs []error) {
globalProperties := data.Except([]interface{}{"applications"})
if data.Has("applications") {
appMaps, ok := data.Get("applications").([]interface{})
if !ok {
errs = append(errs, errors.New("Expected applications to be a list"))
return
}
for _, appData := range appMaps {
if !generic.IsMappable(appData) {
errs = append(errs, errors.NewWithFmt("Expected application to be a list of key/value pairs\nError occurred in manifest near:\n'%s'", appData))
continue
}
appMap := generic.DeepMerge(globalProperties, generic.NewMap(appData))
apps = append(apps, appMap)
}
} else {
apps = append(apps, globalProperties)
}
return
}
示例8: getAuthEndpoint
func (repo CloudControllerUserRepository) getAuthEndpoint() (string, error) {
uaaEndpoint := repo.config.UaaEndpoint()
if uaaEndpoint == "" {
return "", errors.New("UAA endpoint missing from config file")
}
return uaaEndpoint, nil
}
示例9: UploadBuildpack
func (repo *FakeBuildpackBitsRepository) UploadBuildpack(buildpack models.Buildpack, dir string) error {
if repo.UploadBuildpackErr {
return errors.New("Invalid buildpack")
}
repo.UploadBuildpackPath = dir
return repo.UploadBuildpackApiResponse
}
示例10: validateEnvVars
func validateEnvVars(input generic.Map) (errs []error) {
generic.Each(input, func(key, value interface{}) {
if value == nil {
errs = append(errs, errors.New(fmt.Sprintf("env var '%s' should not be null", key)))
}
})
return
}
示例11: normalizeBuildpackArchive
func normalizeBuildpackArchive(inputFile *os.File, outputFile *os.File) error {
stats, err := inputFile.Stat()
if err != nil {
return err
}
reader, err := zip.NewReader(inputFile, stats.Size())
if err != nil {
return err
}
contents := reader.File
parentPath, hasBuildpack := findBuildpackPath(contents)
if !hasBuildpack {
return errors.New("Zip archive does not contain a buildpack")
}
writer := zip.NewWriter(outputFile)
for _, file := range contents {
name := file.Name
if strings.HasPrefix(name, parentPath) {
relativeFilename := strings.TrimPrefix(name, parentPath+"/")
if relativeFilename == "" {
continue
}
fileInfo := file.FileInfo()
header, err := zip.FileInfoHeader(fileInfo)
if err != nil {
return err
}
header.Name = relativeFilename
w, err := writer.CreateHeader(header)
if err != nil {
return err
}
r, err := file.Open()
if err != nil {
return err
}
io.Copy(w, r)
err = r.Close()
if err != nil {
return err
}
}
}
writer.Close()
outputFile.Seek(0, 0)
return nil
}
示例12: GetRequirements
func (cmd CreateService) GetRequirements(reqFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 3 {
err = errors.New("Incorrect Usage")
cmd.ui.FailWithUsage(c, "create-service")
return
}
return
}
示例13: GetRequirements
func (cmd *DeleteApp) GetRequirements(reqFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) == 0 {
err = errors.New("Incorrect Usage")
cmd.ui.FailWithUsage(c, "delete")
return
}
return
}
示例14: Update
func (repo *FakeApplicationRepository) Update(appGuid string, params models.AppParams) (updatedApp models.Application, apiErr error) {
repo.UpdateAppGuid = appGuid
repo.UpdateParams = params
updatedApp = repo.UpdateAppResult
if repo.UpdateErr {
apiErr = errors.New("Error updating app.")
}
return
}
示例15: normalizeBuildpackArchive
func normalizeBuildpackArchive(inputFile *os.File, outputFile *os.File) (err error) {
stats, err := inputFile.Stat()
if err != nil {
return
}
reader, err := zip.NewReader(inputFile, stats.Size())
if err != nil {
return
}
contents := reader.File
parentPath, hasBuildpack := findBuildpackPath(contents)
if !hasBuildpack {
return errors.New("Zip archive does not contain a buildpack")
}
writer := zip.NewWriter(outputFile)
for _, file := range contents {
name := file.Name
if parentPath == "." || strings.HasPrefix(name, parentPath) {
var (
r io.ReadCloser
w io.Writer
header *zip.FileHeader
)
fileInfo := file.FileInfo()
header, err = zip.FileInfoHeader(fileInfo)
header.Name = strings.Replace(name, parentPath+"/", "", 1)
r, err = file.Open()
if err != nil {
return
}
w, err = writer.CreateHeader(header)
if err != nil {
return
}
io.Copy(w, r)
err = r.Close()
if err != nil {
return
}
}
}
writer.Close()
outputFile.Seek(0, 0)
return
}