本文整理匯總了Golang中github.com/wallyworld/core/errors.NotFoundf函數的典型用法代碼示例。如果您正苦於以下問題:Golang NotFoundf函數的具體用法?Golang NotFoundf怎麽用?Golang NotFoundf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NotFoundf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getMirrorReference
// getMirrorReference returns the reference to the metadata file containing mirrors for the specified content and cloud.
func (mirrorRefs *MirrorRefs) getMirrorReference(datatype, contentId string, cloud CloudSpec) (*MirrorReference, error) {
candidates := mirrorRefs.extractMirrorRefs(contentId)
if len(candidates) == 0 {
return nil, errors.NotFoundf("mirror data for %q", contentId)
}
// Restrict by cloud spec and datatype.
hasRightCloud := func(mirrorRef *MirrorReference) bool {
return mirrorRef.hasCloud(cloud) && mirrorRef.DataType == datatype
}
matchingCandidates := candidates.filter(hasRightCloud)
if len(matchingCandidates) == 0 {
// No cloud specific mirrors found so look for a non cloud specific mirror.
for _, candidate := range candidates {
if len(candidate.Clouds) == 0 {
logger.Debugf("using default candidate for content id %q are %v", contentId, candidate)
return &candidate, nil
}
}
return nil, errors.NotFoundf("index file with cloud %v", cloud)
}
logger.Debugf("candidate matches for content id %q are %v", contentId, candidates)
// Pick arbitrary match.
return &matchingCandidates[0], nil
}
示例2: 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
}
示例3: refresh
func (e *Environment) refresh(query *mgo.Query) error {
err := query.One(&e.doc)
if err == mgo.ErrNotFound {
return errors.NotFoundf("environment")
}
return err
}
示例4: AgentTools
// AgentTools returns the tools that the agent is currently running.
// It returns an error that satisfies errors.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
}
示例5: AgentTools
// AgentTools returns the tools that the agent is currently running.
// It an error that satisfies errors.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
}
示例6: runAllowRetriesTest
func (s *BootstrapSuite) runAllowRetriesTest(c *gc.C, test bootstrapRetryTest) {
toolsVersions := envtesting.VAll
if test.version != "" {
useVersion := strings.Replace(test.version, "%LTS%", config.LatestLtsSeries(), 1)
testVersion := version.MustParseBinary(useVersion)
s.PatchValue(&version.Current, testVersion)
if test.addVersionToSource {
toolsVersions = append([]version.Binary{}, toolsVersions...)
toolsVersions = append(toolsVersions, testVersion)
}
}
_, fake := makeEmptyFakeHome(c)
defer fake.Restore()
sourceDir := createToolsSource(c, toolsVersions)
s.PatchValue(&envtools.DefaultBaseURL, sourceDir)
var findToolsRetryValues []bool
mockFindTools := func(cloudInst environs.ConfigGetter, majorVersion, minorVersion int,
filter coretools.Filter, allowRetry bool) (list coretools.List, err error) {
findToolsRetryValues = append(findToolsRetryValues, allowRetry)
return nil, errors.NotFoundf("tools")
}
restore := envtools.TestingPatchBootstrapFindTools(mockFindTools)
defer restore()
_, errc := runCommand(nullContext(c), new(BootstrapCommand), test.args...)
err := <-errc
c.Check(findToolsRetryValues, gc.DeepEquals, test.expectedAllowRetry)
stripped := strings.Replace(err.Error(), "\n", "", -1)
c.Check(stripped, gc.Matches, test.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: bson.D{{"refcount", 1}},
Remove: true,
}, {
C: st.settings.Name,
Id: key,
Remove: true,
}}, nil
}
return []txn.Op{{
C: st.settingsrefs.Name,
Id: key,
Assert: bson.D{{"refcount", bson.D{{"$gt", 1}}}},
Update: bson.D{{"$inc", bson.D{{"refcount", -1}}}},
}}, nil
}
示例8: 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(bson.D{{"_id", name}}).One(udoc)
if err == mgo.ErrNotFound {
err = errors.NotFoundf("user %q", name)
}
return err
}
示例9: 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
}
示例10: ReadInfo
// ReadInfo implements Storage.ReadInfo.
func (m *memStore) ReadInfo(envName string) (EnvironInfo, error) {
m.mu.Lock()
defer m.mu.Unlock()
info := m.envs[envName]
if info != nil {
return info.clone(), nil
}
return nil, errors.NotFoundf("environment %q", envName)
}
示例11: Machine
func (st *fakeState) Machine(id string) (stateMachine, error) {
if err := errorFor("State.Machine", id); err != nil {
return nil, err
}
if m := st.machine(id); m != nil {
return m, nil
}
return nil, errors.NotFoundf("machine %s", id)
}
示例12: Refresh
// Refresh refreshes the contents of the relation from the underlying
// state. It returns an error that satisfies errors.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: TestUpdateEnvironConfigFailsOnConfigValidateError
func (s *ConfigValidatorSuite) TestUpdateEnvironConfigFailsOnConfigValidateError(c *gc.C) {
var configValidatorErr error
s.policy.getConfigValidator = func(string) (state.ConfigValidator, error) {
configValidatorErr = errors.NotFoundf("")
return &s.configValidator, configValidatorErr
}
err := s.updateEnvironConfig(c)
c.Assert(err, gc.ErrorMatches, " not found")
}
示例14: Refresh
// Refresh refreshes the contents of the Unit from the underlying
// state. It an error that satisfies errors.IsNotFound if the unit has
// been removed.
func (u *Unit) Refresh() error {
err := u.st.units.FindId(u.doc.Name).One(&u.doc)
if err == mgo.ErrNotFound {
return errors.NotFoundf("unit %q", u)
}
if err != nil {
return fmt.Errorf("cannot refresh unit %q: %v", u, err)
}
return 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.IsNotFound(err) {
// Lack of constraints indicates lack of unit.
return nil, errors.NotFoundf("unit")
} else if err != nil {
return nil, err
}
return &cons, nil
}