当前位置: 首页>>代码示例>>Golang>>正文


Golang stackerr.HasUnderlying函数代码示例

本文整理汇总了Golang中github.com/facebookgo/stackerr.HasUnderlying函数的典型用法代码示例。如果您正苦于以下问题:Golang HasUnderlying函数的具体用法?Golang HasUnderlying怎么用?Golang HasUnderlying使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了HasUnderlying函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: configFromDir

func configFromDir(dir string) (config, error) {
	l, err := readLegacyConfigFile(filepath.Join(dir, legacyConfigFile))
	if err != nil && !stackerr.HasUnderlying(err, stackerr.MatcherFunc(os.IsNotExist)) {
		return nil, err
	}
	if l != nil { // legacy config format
		projectConfig := &projectConfig{
			Type: legacyParseFormat,
			Parse: &parseProjectConfig{
				JSSDK: l.Global.ParseVersion,
			},
			ParserEmail: l.Global.ParserEmail,
		}
		applications := l.Applications
		if applications == nil {
			applications = make(map[string]*parseAppConfig)
		}
		return &parseConfig{
			Applications:  applications,
			projectConfig: projectConfig,
		}, nil
	}

	canonicalize := func(err error) error {
		if err == nil {
			return nil
		}
		if stackerr.HasUnderlying(err, stackerr.MatcherFunc(os.IsNotExist)) {
			return stackerr.New("Command must be run inside a Parse project.")
		}
		return err
	}

	// current config format
	p, err := readProjectConfigFile(filepath.Join(dir, parseProject))
	if err != nil {
		return nil, canonicalize(err)
	}
	configFile := filepath.Join(dir, parseLocal)
	switch p.Type {
	case parseFormat:
		c, err := readParseConfigFile(configFile)
		if err != nil {
			return nil, canonicalize(err)
		}
		if c.Applications == nil {
			c.Applications = make(map[string]*parseAppConfig)
		}
		c.projectConfig = p
		return c, nil
	}

	return nil, stackerr.Newf("Unknown project type: %d.", p.Type)
}
开发者ID:Georotzen,项目名称:parse-cli,代码行数:54,代码来源:config.go

示例2: TestApplyWithExistingRemoveError

func TestApplyWithExistingRemoveError(t *testing.T) {
	const image = "x"
	givenErr := errors.New("")
	container := &Container{
		containerConfig: &dockerclient.ContainerConfig{
			Image: image,
		},
		removeExisting: true,
	}
	client := &mockClient{
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return &dockerclient.ContainerInfo{
				Id:    "y",
				Image: "z",
			}, nil
		},
		listImages: func() ([]*dockerclient.Image, error) {
			return []*dockerclient.Image{
				{
					RepoTags: []string{image},
					Id:       "y",
				},
			}, nil
		},
		removeContainer: func(id string, force, volumes bool) error {
			return givenErr
		},
	}
	err := container.Apply(client)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
开发者ID:hopkings2008,项目名称:dockerutil,代码行数:31,代码来源:dockergoal_test.go

示例3: main

func main() {
	rx := regexp.MustCompile(os.Args[1])

	r := mllp.NewReader(os.Stdin)
	w := mllp.NewWriter(os.Stdout)

	i := 0
	for {
		m, err := r.ReadMessage()
		if err != nil {
			if stackerr.HasUnderlying(err, stackerr.Equals(io.EOF)) {
				break
			}

			panic(err)
		}

		if rx.Match(m) {
			if err := w.WriteMessage(m); err != nil {
				panic(err)
			}
		}

		i++
	}
}
开发者ID:deoxxa,项目名称:mllp,代码行数:26,代码来源:main.go

示例4: TestApplyStartError

func TestApplyStartError(t *testing.T) {
	givenErr := errors.New("")
	const image = "x"
	const id = "y"
	container := &Container{
		containerConfig: &dockerclient.ContainerConfig{
			Image: image,
		},
	}
	client := &mockClient{
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return &dockerclient.ContainerInfo{
				Id:     "a",
				Image:  id,
				Config: &dockerclient.ContainerConfig{},
			}, nil
		},
		listImages: func() ([]*dockerclient.Image, error) {
			return []*dockerclient.Image{
				{
					RepoTags: []string{image},
					Id:       id,
				},
			}, nil
		},
		startContainer: func(id string, config *dockerclient.HostConfig) error {
			return givenErr
		},
	}
	err := container.Apply(client)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
开发者ID:hopkings2008,项目名称:dockerutil,代码行数:32,代码来源:dockergoal_test.go

示例5: TestApplyInitialInspectError

func TestApplyInitialInspectError(t *testing.T) {
	givenErr := errors.New("")
	container := &Container{
		containerConfig: &dockerclient.ContainerConfig{
			Image: "x",
		},
	}
	client := &mockClient{
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return nil, givenErr
		},
	}
	err := container.Apply(client)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
开发者ID:hopkings2008,项目名称:dockerutil,代码行数:15,代码来源:dockergoal_test.go

示例6: TestApplyGraphApplyError

func TestApplyGraphApplyError(t *testing.T) {
	givenErr := errors.New("")
	containers := []*Container{
		{
			name:            "n1",
			containerConfig: &dockerclient.ContainerConfig{Image: "in1"},
		},
	}
	client := &mockClient{
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return nil, givenErr
		},
	}
	err := ApplyGraph(client, containers)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
开发者ID:hopkings2008,项目名称:dockerutil,代码行数:16,代码来源:dockergoal_test.go

示例7: TestApplyInspectAfterCreateError

func TestApplyInspectAfterCreateError(t *testing.T) {
	container, err := NewContainer(
		ContainerName("x"),
		ContainerConfig(&dockerclient.ContainerConfig{Image: "foo"}),
	)
	ensure.Nil(t, err)
	client := &mockClient{
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return nil, dockerclient.ErrNotFound
		},
		createContainer: func(config *dockerclient.ContainerConfig, name string) (string, error) {
			return "baz", nil
		},
	}
	err = container.Apply(client)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(dockerclient.ErrNotFound)))
}
开发者ID:hopkings2008,项目名称:dockerutil,代码行数:17,代码来源:dockergoal_test.go

示例8: TestCheckExistingImageIdentifyError

func TestCheckExistingImageIdentifyError(t *testing.T) {
	givenErr := errors.New("")
	const image = "x"
	container := &Container{
		containerConfig: &dockerclient.ContainerConfig{
			Image: image,
		},
	}
	client := &mockClient{
		listImages: func() ([]*dockerclient.Image, error) {
			return nil, givenErr
		},
	}
	ok, err := container.checkExisting(client, &dockerclient.ContainerInfo{Image: "z"})
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
	ensure.False(t, ok)
}
开发者ID:hopkings2008,项目名称:dockerutil,代码行数:17,代码来源:dockergoal_test.go

示例9: PrettyPrintApps

func (c *HerokuConfig) PrettyPrintApps(e *Env) {
	apps := c.Applications

	defaultApp := c.GetDefaultApp()

	var appNames []string
	for appName := range apps {
		appNames = append(appNames, appName)
	}
	sort.Strings(appNames)

	if len(appNames) == 0 {
		return
	}

	fmt.Fprintln(
		e.Out,
		"The following apps are associated with cloud code in the current directory:",
	)

	for _, appName := range appNames {
		if appName == DefaultKey {
			continue
		}
		if defaultApp == appName {
			fmt.Fprint(e.Out, "* ")
		} else {
			fmt.Fprint(e.Out, "  ")
		}
		fmt.Fprintf(e.Out, "%s", appName)

		config, _ := apps[appName]
		if config.GetLink() != "" {
			fmt.Fprintf(e.Out, " -> %s", config.GetLink())
		}
		herokuAppName, err := FetchHerokuAppName(config.HerokuAppID, e)
		if err != nil {
			if stackerr.HasUnderlying(err, stackerr.MatcherFunc(HerokuAppNotFound)) {
				herokuAppName = ""
			} else {
				herokuAppName = config.HerokuAppID
			}
		}
		fmt.Fprintf(e.Out, " (%q)\n", herokuAppName)
	}
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:46,代码来源:heroku_config.go

示例10: authUser

func (l *login) authUser(e *env) error {
	_, err := l.authUserWithToken(e)
	if err == nil {
		return nil
	}

	// user never created an account key: educate them
	if stackerr.HasUnderlying(err, stackerr.MatcherFunc(os.IsNotExist)) {
		fmt.Fprintln(
			e.Out,
			`We've changed the way the CLI works.
To save time logging in, you should create an account key.
`)
	}

	apps := &apps{}
	fmt.Fprintln(
		e.Out,
		`Type "parse configure accountkey" to create a new account key.
Read more at: https://parse.com/docs/js/guide#command-line-account-keys

Please login to Parse using your email and password.`,
	)
	for i := 0; i < numRetries; i++ {
		err := l.populateCreds(e)
		if err != nil {
			return err
		}
		apps.login.credentials = l.credentials
		_, err = apps.restFetchApps(e)
		if err == nil {
			return nil
		}

		if i == numRetries-1 && err != nil {
			return err
		}
		if err != errAuth {
			fmt.Fprintf(e.Err, "Got error: %s", errorString(e, err))
		}
		fmt.Fprintf(e.Err, "%s\nPlease try again...\n", err)
		l.credentials.password = ""
	}
	return errAuth
}
开发者ID:hassanabidpk,项目名称:parse-cli,代码行数:45,代码来源:login.go

示例11: TestApplyRemovesExistingWithoutDesiredImageError

func TestApplyRemovesExistingWithoutDesiredImageError(t *testing.T) {
	givenErr := errors.New("")
	container := &Container{
		containerConfig: &dockerclient.ContainerConfig{
			Image: "x",
		},
	}
	client := &mockClient{
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return &dockerclient.ContainerInfo{Id: "y", Image: "a"}, nil
		},
		listImages: func() ([]*dockerclient.Image, error) {
			return nil, givenErr
		},
	}
	err := container.Apply(client)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
开发者ID:hopkings2008,项目名称:dockerutil,代码行数:18,代码来源:dockergoal_test.go

示例12: authUserWithToken

func (l *login) authUserWithToken(e *env) (string, error) {
	_, tokenCredentials, err := l.getTokenCredentials(e, e.ParserEmail)
	if err != nil {
		if stackerr.HasUnderlying(err, stackerr.MatcherFunc(accessKeyNotFound)) {
			fmt.Fprintln(e.Err, errorString(e, err))
		}
		return "", err
	}

	email, err := l.authToken(e, tokenCredentials.token)
	if err != nil {
		fmt.Fprintf(e.Err, "Account key could not be used.\nError: %s\n\n", errorString(e, err))
		return "", err
	}

	l.credentials = *tokenCredentials
	return email, nil
}
开发者ID:hassanabidpk,项目名称:parse-cli,代码行数:18,代码来源:login.go

示例13: TestApplyForceRemoveExistingError

func TestApplyForceRemoveExistingError(t *testing.T) {
	container, err := NewContainer(
		ContainerName("x"),
		ContainerConfig(&dockerclient.ContainerConfig{Image: "foo"}),
		ContainerForceRemoveExisting(),
	)
	ensure.Nil(t, err)
	givenErr := errors.New("")
	client := &mockClient{
		removeContainer: func(id string, force, volumes bool) error {
			return givenErr
		},
		inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
			return &dockerclient.ContainerInfo{Id: "x"}, nil
		},
	}
	err = container.Apply(client)
	ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
开发者ID:hopkings2008,项目名称:dockerutil,代码行数:19,代码来源:dockergoal_test.go

示例14: AuthUser

func (l *Login) AuthUser(e *Env, strict bool) error {
	_, err := l.AuthUserWithToken(e, strict)
	if err == nil {
		return nil
	}
	if strict {
		return err
	}

	if !stackerr.HasUnderlying(err, stackerr.MatcherFunc(accountKeyNotConfigured)) {
		fmt.Fprintln(
			e.Out,
			`Type "parse configure accountkey" to create a new account key.
Read more at: https://parse.com/docs/cloudcode/guide#command-line-account-keys

Please login to Parse using your email and password.`,
		)
	}

	apps := &Apps{}
	for i := 0; i < numRetries; i++ {
		err := l.populateCreds(e)
		if err != nil {
			return err
		}
		apps.Login.Credentials = l.Credentials
		_, err = apps.RestFetchApps(e)
		if err == nil {
			return nil
		}

		if i == numRetries-1 && err != nil {
			return err
		}
		if err != errAuth {
			fmt.Fprintf(e.Err, "Got error: %s", ErrorString(e, err))
		}
		fmt.Fprintf(e.Err, "%s\nPlease try again...\n", err)
		l.Credentials.Password = ""
	}
	return errAuth
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:42,代码来源:login.go

示例15: herokuAppNames

func (h *herokuLink) herokuAppNames(ids []string, e *parsecli.Env) (nameIDs, []string, error) {
	var wg errgroup.Group
	wg.Add(len(ids))
	maxParallel := make(chan struct{}, maxRequests)

	var (
		ret               nameIDs
		deletedLinks      []string
		retMutex          sync.Mutex
		deletedLinksMutex sync.Mutex
	)

	getAppName := func(id string) {
		defer func() {
			wg.Done()
			<-maxParallel
		}()
		appName, err := parsecli.FetchHerokuAppName(id, e)
		if err != nil {
			if stackerr.HasUnderlying(err, stackerr.MatcherFunc(parsecli.HerokuAppNotFound)) {
				deletedLinksMutex.Lock()
				defer deletedLinksMutex.Unlock()
				deletedLinks = append(deletedLinks, id)
				return
			}
			wg.Error(err) // ignore error if corresponding heroku app was deleted
			return
		}

		retMutex.Lock()
		defer retMutex.Unlock()
		ret = append(ret, nameID{id: id, name: appName})
	}

	for _, id := range ids {
		go getAppName(id)
	}
	err := wg.Wait()
	sort.Sort(ret)
	return ret, deletedLinks, stackerr.Wrap(err)
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:41,代码来源:link.go


注:本文中的github.com/facebookgo/stackerr.HasUnderlying函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。