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


Golang errors.NewModelNotFoundError函數代碼示例

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


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

示例1: FindByUsername

func (repo CloudControllerUserRepository) FindByUsername(username string) (models.UserFields, error) {
	uaaEndpoint, apiErr := repo.getAuthEndpoint()
	var user models.UserFields
	if apiErr != nil {
		return user, apiErr
	}

	usernameFilter := neturl.QueryEscape(fmt.Sprintf(`userName Eq "%s"`, username))
	path := fmt.Sprintf("%s/Users?attributes=id,userName&filter=%s", uaaEndpoint, usernameFilter)
	users, apiErr := repo.updateOrFindUsersWithUAAPath([]models.UserFields{}, path)

	if apiErr != nil {
		errType, ok := apiErr.(errors.HttpError)
		if ok {
			if errType.StatusCode() == 403 {
				return user, errors.NewAccessDeniedError()
			}
		}
		return user, apiErr
	} else if len(users) == 0 {
		return user, errors.NewModelNotFoundError("User", username)
	}

	return users[0], apiErr
}
開發者ID:ArthurHlt,項目名稱:cloudfoundry-cli,代碼行數:25,代碼來源:users.go

示例2: Read

func (repo cloudControllerSecurityGroupRepo) Read(name string) (models.SecurityGroup, error) {
	path := fmt.Sprintf("/v2/security_groups?q=%s&inline-relations-depth=2", url.QueryEscape("name:"+name))
	group := models.SecurityGroup{}
	foundGroup := false

	err := repo.gateway.ListPaginatedResources(
		repo.config.ApiEndpoint(),
		path,
		resources.SecurityGroupResource{},
		func(resource interface{}) bool {
			if asgr, ok := resource.(resources.SecurityGroupResource); ok {
				group = asgr.ToModel()
				foundGroup = true
			}

			return false
		},
	)
	if err != nil {
		return group, err
	}

	if !foundGroup {
		err = errors.NewModelNotFoundError("security group", name)
	}

	return group, err
}
開發者ID:tools-alexuser01,項目名稱:cli,代碼行數:28,代碼來源:security_groups.go

示例3: Find

func (repo CloudControllerRouteRepository) Find(host string, domain models.DomainFields, path string, port int) (models.Route, error) {
	var route models.Route
	queryString := queryStringForRouteSearch(host, domain.GUID, path, port)

	q := struct {
		Query                string `url:"q"`
		InlineRelationsDepth int    `url:"inline-relations-depth"`
	}{queryString, 1}

	opt, _ := query.Values(q)

	found := false
	apiErr := repo.gateway.ListPaginatedResources(
		repo.config.APIEndpoint(),
		fmt.Sprintf("/v2/routes?%s", opt.Encode()),
		resources.RouteResource{},
		func(resource interface{}) bool {
			keepSearching := true
			route = resource.(resources.RouteResource).ToModel()
			if doesNotMatchVersionSpecificAttributes(route, path, port) {
				return keepSearching
			}

			found = true
			return !keepSearching
		})

	if apiErr == nil && !found {
		apiErr = errors.NewModelNotFoundError("Route", host)
	}

	return route, apiErr
}
開發者ID:yingkitw,項目名稱:cli,代碼行數:33,代碼來源:routes.go

示例4: FindInstanceByName

func (repo CloudControllerServiceRepository) FindInstanceByName(name string) (instance models.ServiceInstance, apiErr error) {
	path := fmt.Sprintf("%s/v2/spaces/%s/service_instances?return_user_provided_service_instances=true&q=%s&inline-relations-depth=1", repo.config.APIEndpoint(), repo.config.SpaceFields().GUID, url.QueryEscape("name:"+name))

	responseJSON := new(resources.PaginatedServiceInstanceResources)
	apiErr = repo.gateway.GetResource(path, responseJSON)
	if apiErr != nil {
		return
	}

	if len(responseJSON.Resources) == 0 {
		apiErr = errors.NewModelNotFoundError("Service instance", name)
		return
	}

	instanceResource := responseJSON.Resources[0]
	instance = instanceResource.ToModel()

	if instanceResource.Entity.ServicePlan.Metadata.GUID != "" {
		resource := &resources.ServiceOfferingResource{}
		path = fmt.Sprintf("%s/v2/services/%s", repo.config.APIEndpoint(), instanceResource.Entity.ServicePlan.Entity.ServiceOfferingGUID)
		apiErr = repo.gateway.GetResource(path, resource)
		instance.ServiceOffering = resource.ToFields()
	}

	return
}
開發者ID:Reejoshi,項目名稱:cli,代碼行數:26,代碼來源:services.go

示例5: FindByName

func (repo *FakeBuildpackRepository) FindByName(name string) (buildpack models.Buildpack, apiErr error) {
	repo.FindByNameName = name
	buildpack = repo.FindByNameBuildpack

	if repo.FindByNameNotFound {
		apiErr = errors.NewModelNotFoundError("Buildpack", name)
	}

	return
}
開發者ID:Jack1996,項目名稱:cli,代碼行數:10,代碼來源:fake_buildpack_repo.go

示例6: FindByUsername

func (repo *FakeUserRepository) FindByUsername(username string) (user models.UserFields, apiErr error) {
	repo.FindByUsernameUsername = username
	user = repo.FindByUsernameUserFields

	if repo.FindByUsernameNotFound {
		apiErr = errors.NewModelNotFoundError("User", "")
	}

	return
}
開發者ID:ArthurHlt,項目名稱:cloudfoundry-cli,代碼行數:10,代碼來源:fake_user_repo.go

示例7: FindByName

func (repo *FakeServiceBrokerRepo) FindByName(name string) (serviceBroker models.ServiceBroker, apiErr error) {
	repo.FindByNameName = name
	serviceBroker = repo.FindByNameServiceBroker

	if repo.FindByNameNotFound {
		apiErr = errors.NewModelNotFoundError("Service Broker", name)
	}

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

示例8: FindByGuid

func (repo *FakeServiceBrokerRepo) FindByGuid(guid string) (serviceBroker models.ServiceBroker, apiErr error) {
	repo.FindByGuidGuid = guid
	serviceBroker = repo.FindByGuidServiceBroker

	if repo.FindByGuidNotFound {
		apiErr = errors.NewModelNotFoundError("Service Broker", guid)
	}

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

示例9: FindServiceOfferingsForSpaceByLabel

func (repo CloudControllerServiceRepository) FindServiceOfferingsForSpaceByLabel(spaceGUID, name string) (offerings models.ServiceOfferings, err error) {
	offerings, err = repo.getServiceOfferings(fmt.Sprintf("/v2/spaces/%s/services?q=%s", spaceGUID, url.QueryEscape("label:"+name)))

	if httpErr, ok := err.(errors.HTTPError); ok && httpErr.ErrorCode() == errors.BadQueryParameter {
		offerings, err = repo.findServiceOfferingsByPaginating(spaceGUID, name)
	}

	if err == nil && len(offerings) == 0 {
		err = errors.NewModelNotFoundError("Service offering", name)
	}

	return
}
開發者ID:Reejoshi,項目名稱:cli,代碼行數:13,代碼來源:services.go

示例10: FindByNameInOrg

func (repo CloudControllerDomainRepository) FindByNameInOrg(name string, orgGuid string) (domain models.DomainFields, apiErr error) {
	domain, apiErr = repo.findOneWithPath(repo.strategy.OrgDomainURL(orgGuid, name), name)

	switch apiErr.(type) {
	case *errors.ModelNotFoundError:
		domain, apiErr = repo.FindSharedByName(name)
		if !domain.Shared {
			apiErr = errors.NewModelNotFoundError("Domain", name)
		}
	}

	return
}
開發者ID:vframbach,項目名稱:cli,代碼行數:13,代碼來源:domains.go

示例11: FindPrivateByName

func (repo *FakeDomainRepository) FindPrivateByName(name string) (domain models.DomainFields, apiErr error) {
	repo.FindPrivateByNameName = name
	domain = repo.FindPrivateByNameDomain

	if repo.FindPrivateByNameNotFound {
		apiErr = errors.NewModelNotFoundError("Domain", name)
	}
	if repo.FindPrivateByNameErr {
		apiErr = errors.New("Error finding domain")
	}

	return
}
開發者ID:Doebe,項目名稱:workplace,代碼行數:13,代碼來源:fake_domain_repo.go

示例12: FindServiceOfferingByLabelAndProvider

func (repo CloudControllerServiceRepository) FindServiceOfferingByLabelAndProvider(label, provider string) (models.ServiceOffering, error) {
	path := fmt.Sprintf("/v2/services?q=%s", url.QueryEscape("label:"+label+";provider:"+provider))
	offerings, apiErr := repo.getServiceOfferings(path)

	if apiErr != nil {
		return models.ServiceOffering{}, apiErr
	} else if len(offerings) == 0 {
		apiErr = errors.NewModelNotFoundError("Service offering", label+" "+provider)
		return models.ServiceOffering{}, apiErr
	}

	return offerings[0], apiErr
}
開發者ID:Reejoshi,項目名稱:cli,代碼行數:13,代碼來源:services.go

示例13: FindServiceOfferingsForSpaceByLabel

func (repo CloudControllerServiceRepository) FindServiceOfferingsForSpaceByLabel(spaceGuid, name string) (offerings models.ServiceOfferings, err error) {
	offerings, err = repo.getServiceOfferings(
		fmt.Sprintf("/v2/spaces/%s/services?q=%s&inline-relations-depth=1", spaceGuid, url.QueryEscape("label:"+name)))

	if httpErr, ok := err.(errors.HttpError); ok && httpErr.ErrorCode() == errors.BAD_QUERY_PARAM {
		offerings, err = repo.findServiceOfferingsByPaginating(spaceGuid, name)
	}

	if err == nil && len(offerings) == 0 {
		err = errors.NewModelNotFoundError("Service offering", name)
	}

	return
}
開發者ID:EthanWu,項目名稱:cli,代碼行數:14,代碼來源:services.go

示例14: findOneWithPath

func (repo CloudControllerDomainRepository) findOneWithPath(path, name string) (domain models.DomainFields, apiErr error) {
	foundDomain := false
	apiErr = repo.listDomains(path, func(result models.DomainFields) bool {
		domain = result
		foundDomain = true
		return false
	})

	if apiErr == nil && !foundDomain {
		apiErr = errors.NewModelNotFoundError("Domain", name)
	}

	return
}
開發者ID:vframbach,項目名稱:cli,代碼行數:14,代碼來源:domains.go

示例15: FindByGuid

func (repo CloudControllerSpaceQuotaRepository) FindByGuid(guid string) (quota models.SpaceQuota, apiErr error) {
	quotas, apiErr := repo.FindByOrg(repo.config.OrganizationFields().Guid)
	if apiErr != nil {
		return
	}

	for _, quota := range quotas {
		if quota.Guid == guid {
			return quota, nil
		}
	}

	apiErr = errors.NewModelNotFoundError("Space Quota", guid)
	return models.SpaceQuota{}, apiErr
}
開發者ID:vframbach,項目名稱:cli,代碼行數:15,代碼來源:space_quotas.go


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