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


Golang errors.NotFoundf函數代碼示例

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


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

示例1: fetchData

// fetchData gets all the data from the given path relative to the given base URL.
// It returns the data found and the full URL used.
func fetchData(baseURL, path string, requireSigned bool) (data []byte, dataURL string, err error) {
	dataURL = baseURL
	if !strings.HasSuffix(dataURL, "/") {
		dataURL += "/"
	}
	dataURL += path
	resp, err := http.Get(dataURL)
	if err != nil {
		return nil, dataURL, errors.NotFoundf("invalid URL %q", dataURL)
	}
	defer resp.Body.Close()
	if resp.StatusCode == http.StatusNotFound {
		return nil, dataURL, errors.NotFoundf("cannot find URL %q", dataURL)
	}
	if resp.StatusCode == http.StatusUnauthorized {
		return nil, dataURL, errors.Unauthorizedf("unauthorised access to URL %q", dataURL)
	}
	if resp.StatusCode != http.StatusOK {
		return nil, dataURL, fmt.Errorf("cannot access URL %q, %q", dataURL, resp.Status)
	}

	if requireSigned {
		data, err = DecodeCheckSignature(resp.Body)
	} else {
		data, err = ioutil.ReadAll(resp.Body)
	}
	if err != nil {
		return nil, dataURL, fmt.Errorf("cannot read URL data, %v", err)
	}
	return data, dataURL, nil
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:33,代碼來源:simplestreams.go

示例2: getImageIdsPath

// getImageIdsPath returns the path to the metadata file containing image ids the specified constraint.
func (indexRef *indexReference) getImageIdsPath(ic *ImageConstraint) (string, error) {
	prodIds, err := ic.Ids()
	if err != nil {
		return "", err
	}
	var containsImageIds bool
	for _, metadata := range indexRef.Indexes {
		if metadata.DataType != imageIds {
			continue
		}
		containsImageIds = true
		var cloudSpecMatches bool
		for _, cs := range metadata.Clouds {
			if cs == ic.CloudSpec {
				cloudSpecMatches = true
				break
			}
		}
		var prodSpecMatches bool
		for _, pid := range metadata.ProductIds {
			if containsString(prodIds, pid) {
				prodSpecMatches = true
				break
			}
		}
		if cloudSpecMatches && prodSpecMatches {
			return metadata.ProductsFilePath, nil
		}
	}
	if !containsImageIds {
		return "", errors.NotFoundf("index file missing %q data", imageIds)
	}
	return "", errors.NotFoundf("index file missing data for cloud %v and product name(s) %q", ic.CloudSpec, prodIds)
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:35,代碼來源:simplestreams.go

示例3: AgentTools

// AgentTools returns the tools that the agent is currently running.
// It an error that satisfies IsNotFound if the tools have not yet been set.
func (u *Unit) AgentTools() (*tools.Tools, error) {
	if u.doc.Tools == nil {
		return nil, errors.NotFoundf("agent tools for unit %q", u)
	}
	tools := *u.doc.Tools
	return &tools, nil
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:9,代碼來源:unit.go

示例4: getUser

// getUser fetches information about the user with the
// given name into the provided userDoc.
func (st *State) getUser(name string, udoc *userDoc) error {
	err := st.users.Find(D{{"_id", name}}).One(udoc)
	if err == mgo.ErrNotFound {
		err = errors.NotFoundf("user %q", name)
	}
	return err
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:9,代碼來源:user.go

示例5: removeSettings

// removeSettings removes the Settings for key.
func removeSettings(st *State, key string) error {
	err := st.settings.RemoveId(key)
	if err == mgo.ErrNotFound {
		return errors.NotFoundf("settings")
	}
	return nil
}
開發者ID:hivetech,項目名稱:judo.legacy,代碼行數:8,代碼來源:settings.go

示例6: FindEntity

// FindEntity returns the entity with the given tag.
//
// The returned value can be of type *Machine, *Unit,
// *User, *Service or *Environment, depending
// on the tag.
func (st *State) FindEntity(tag string) (Entity, error) {
	kind, id, err := names.ParseTag(tag, "")
	// TODO(fwereade): when lp:1199352 (relation lacks Tag) is fixed, add
	// support for relation entities here.
	switch kind {
	case names.MachineTagKind:
		return st.Machine(id)
	case names.UnitTagKind:
		return st.Unit(id)
	case names.UserTagKind:
		return st.User(id)
	case names.ServiceTagKind:
		return st.Service(id)
	case names.EnvironTagKind:
		conf, err := st.EnvironConfig()
		if err != nil {
			return nil, err
		}
		// Return an invalid entity error if the requested environment is not
		// the current one.
		if id != conf.Name() {
			return nil, errors.NotFoundf("environment %q", id)
		}
		return st.Environment()
	}
	return nil, err
}
開發者ID:hivetech,項目名稱:judo.legacy,代碼行數:32,代碼來源:state.go

示例7: settingsDecRefOps

// settingsDecRefOps returns a list of operations that decrement the
// ref count of the service settings identified by serviceName and
// curl. If the ref count is set to zero, the appropriate setting and
// ref count documents will both be deleted.
func settingsDecRefOps(st *State, serviceName string, curl *charm.URL) ([]txn.Op, error) {
	key := serviceSettingsKey(serviceName, curl)
	var doc settingsRefsDoc
	if err := st.settingsrefs.FindId(key).One(&doc); err == mgo.ErrNotFound {
		return nil, errors.NotFoundf("service %q settings for charm %q", serviceName, curl)
	} else if err != nil {
		return nil, err
	}
	if doc.RefCount == 1 {
		return []txn.Op{{
			C:      st.settingsrefs.Name,
			Id:     key,
			Assert: D{{"refcount", 1}},
			Remove: true,
		}, {
			C:      st.settings.Name,
			Id:     key,
			Remove: true,
		}}, nil
	}
	return []txn.Op{{
		C:      st.settingsrefs.Name,
		Id:     key,
		Assert: D{{"refcount", D{{"$gt", 1}}}},
		Update: D{{"$inc", D{{"refcount", -1}}}},
	}}, nil
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:31,代碼來源:service.go

示例8: AgentTools

// AgentTools returns the tools that the agent is currently running.
// It returns an error that satisfies IsNotFound if the tools have not yet been set.
func (m *Machine) AgentTools() (*tools.Tools, error) {
	if m.doc.Tools == nil {
		return nil, errors.NotFoundf("agent tools for machine %v", m)
	}
	tools := *m.doc.Tools
	return &tools, nil
}
開發者ID:hivetech,項目名稱:judo.legacy,代碼行數:9,代碼來源:machine.go

示例9: Lifer

func (st *fakeLifeState) Lifer(tag string) (state.Lifer, error) {
	if lifer, ok := st.entities[tag]; ok {
		if lifer.err != nil {
			return nil, lifer.err
		}
		return lifer, nil
	}
	return nil, errors.NotFoundf("entity %q", tag)
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:9,代碼來源:life_test.go

示例10: readConstraints

func readConstraints(st *State, id string) (constraints.Value, error) {
	doc := constraintsDoc{}
	if err := st.constraints.FindId(id).One(&doc); err == mgo.ErrNotFound {
		return constraints.Value{}, errors.NotFoundf("constraints")
	} else if err != nil {
		return constraints.Value{}, err
	}
	return doc.value(), nil
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:9,代碼來源:constraints.go

示例11: Remover

func (st *fakeRemoverState) Remover(tag string) (state.Remover, error) {
	if remover, ok := st.entities[tag]; ok {
		if remover.err != nil {
			return nil, remover.err
		}
		return remover, nil
	}
	return nil, errors.NotFoundf("entity %q", tag)
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:9,代碼來源:remove_test.go

示例12: Refresh

// Refresh refreshes the contents of the relation from the underlying
// state. It returns an error that satisfies IsNotFound if the relation has been
// removed.
func (r *Relation) Refresh() error {
	doc := relationDoc{}
	err := r.st.relations.FindId(r.doc.Key).One(&doc)
	if err == mgo.ErrNotFound {
		return errors.NotFoundf("relation %v", r)
	}
	if err != nil {
		return fmt.Errorf("cannot refresh relation %v: %v", r, err)
	}
	if r.doc.Id != doc.Id {
		// The relation has been destroyed and recreated. This is *not* the
		// same relation; if we pretend it is, we run the risk of violating
		// the lifecycle-only-advances guarantee.
		return errors.NotFoundf("relation %v", r)
	}
	r.doc = doc
	return nil
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:21,代碼來源:relation.go

示例13: Refresh

// Refresh refreshes the contents of the Service from the underlying
// state. It returns an error that satisfies IsNotFound if the service has
// been removed.
func (s *Service) Refresh() error {
	err := s.st.services.FindId(s.doc.Name).One(&s.doc)
	if err == mgo.ErrNotFound {
		return errors.NotFoundf("service %q", s)
	}
	if err != nil {
		return fmt.Errorf("cannot refresh service %q: %v", s, err)
	}
	return nil
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:13,代碼來源:service.go

示例14: FindEntity

func (st *fakeState) FindEntity(tag string) (state.Entity, error) {
	entity, ok := st.entities[tag]
	if !ok {
		return nil, errors.NotFoundf("entity %q", tag)
	}
	if err := entity.error(); err != nil {
		return nil, err
	}
	return entity, nil
}
開發者ID:hivetech,項目名稱:judo.legacy,代碼行數:10,代碼來源:password_test.go

示例15: constraints

// constraints is a helper function to return a unit's deployment constraints.
func (u *Unit) constraints() (*constraints.Value, error) {
	cons, err := readConstraints(u.st, u.globalKey())
	if errors.IsNotFoundError(err) {
		// Lack of constraints indicates lack of unit.
		return nil, errors.NotFoundf("unit")
	} else if err != nil {
		return nil, err
	}
	return &cons, nil
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:11,代碼來源:unit.go


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