本文整理汇总了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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}