• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang client.NewClient函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: mantaFactory

func mantaFactory(conf map[string]string) (Client, error) {
	path, ok := conf["path"]
	if !ok {
		return nil, fmt.Errorf("missing 'path' configuration")
	}

	objectName, ok := conf["objectName"]
	if !ok {
		objectName = DEFAULT_OBJECT_NAME
	}

	creds, err := getCredentialsFromEnvironment()

	if err != nil {
		return nil, fmt.Errorf("Error getting Manta credentials: %s", err.Error())
	}

	client := manta.New(joyentclient.NewClient(
		creds.MantaEndpoint.URL,
		"",
		creds,
		log.New(os.Stderr, "", log.LstdFlags),
	))

	return &MantaClient{
		Client:     client,
		Path:       path,
		ObjectName: objectName,
	}, nil
}
开发者ID:partamonov,项目名称:terraform,代码行数:30,代码来源:manta.go


示例2: newCompute

func newCompute(cloud environs.CloudSpec) (*joyentCompute, error) {
	creds, err := credentials(cloud)
	if err != nil {
		return nil, err
	}
	client := client.NewClient(cloud.Endpoint, cloudapi.DefaultAPIVersion, creds, newGoLogger())
	return &joyentCompute{cloudapi: cloudapi.New(client)}, nil
}
开发者ID:bac,项目名称:juju,代码行数:8,代码来源:environ_instance.go


示例3: TestSignURL

func (s *ClientSuite) TestSignURL(c *gc.C) {
	cl := client.NewClient(s.creds.MantaEndpoint.URL, "", s.creds, nil)
	c.Assert(cl, gc.NotNil)

	path := fmt.Sprintf("/%s/stor", s.creds.UserAuthentication.User)
	singedUrl, err := cl.SignURL(path, time.Now().Add(time.Minute*5))
	c.Assert(err, gc.IsNil)
	c.Assert(singedUrl, gc.Not(gc.Equals), "")
}
开发者ID:asteris-llc,项目名称:gocommon,代码行数:9,代码来源:client_test.go


示例4: TestSendRequest

func (s *ClientSuite) TestSendRequest(c *gc.C) {
	cl := client.NewClient(s.creds.SdcEndpoint.URL, "", s.creds, nil)
	c.Assert(cl, gc.NotNil)

	req := joyenthttp.RequestData{}
	resp := joyenthttp.ResponseData{ExpectedStatus: []int{http.StatusOK}}
	err := cl.SendRequest(client.GET, "", "", &req, &resp)
	c.Assert(err, gc.IsNil)
}
开发者ID:asteris-llc,项目名称:gocommon,代码行数:9,代码来源:client_test.go


示例5: newCompute

func newCompute(cfg *environConfig) (*joyentCompute, error) {
	creds, err := credentials(cfg)
	if err != nil {
		return nil, err
	}
	client := client.NewClient(cfg.sdcUrl(), cloudapi.DefaultAPIVersion, creds, &logger)

	return &joyentCompute{
		ecfg:     cfg,
		cloudapi: cloudapi.New(client)}, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:11,代码来源:environ_instance.go


示例6: Cloud

// Cloud returns a configured cloudapi.Client instance
func (c *Config) Cloud() (*cloudapi.Client, error) {
	creds, err := c.Creds()
	if err != nil {
		return nil, err
	}

	return cloudapi.New(client.NewClient(
		c.URL,
		cloudapi.DefaultAPIVersion,
		creds,
		&cloudapi.Logger,
	)), nil
}
开发者ID:cehoffman,项目名称:triton-terraform,代码行数:14,代码来源:config.go


示例7: newStorage

func newStorage(cfg *environConfig, name string) (storage.Storage, error) {
	creds, err := credentials(cfg)
	if err != nil {
		return nil, err
	}
	client := client.NewClient(cfg.mantaUrl(), "", creds, &logger)

	if name == "" {
		name = cfg.controlDir()
	}

	return &JoyentStorage{
		ecfg:          cfg,
		containerName: name,
		manta:         manta.New(client)}, nil
}
开发者ID:jiasir,项目名称:juju,代码行数:16,代码来源:storage.go


示例8: getSDCClient

func (c SDCConfig) getSDCClient() (*cloudapi.Client, error) {
	userauth, err := auth.NewAuth(c.Account, c.KeyMaterial, "rsa-sha256")
	if err != nil {
		return nil, err
	}

	creds := &auth.Credentials{
		UserAuthentication: userauth,
		SdcKeyId:           c.KeyID,
		SdcEndpoint:        auth.Endpoint{URL: c.URL},
	}

	client := cloudapi.New(client.NewClient(
		c.URL,
		cloudapi.DefaultAPIVersion,
		creds,
		log.New(os.Stderr, "", log.LstdFlags),
	))

	return client, nil
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:21,代码来源:provider.go


示例9: CreateTritonClient

// CreateTritonClient returns an SDC client configured with the appropriate client credentials
// or an error if creating the client fails.
func (c *AccessConfig) CreateTritonClient() (*cloudapi.Client, error) {
	keyData, err := processKeyMaterial(c.KeyMaterial)
	if err != nil {
		return nil, err
	}

	userauth, err := auth.NewAuth(c.Account, string(keyData), "rsa-sha256")
	if err != nil {
		return nil, err
	}

	creds := &auth.Credentials{
		UserAuthentication: userauth,
		SdcKeyId:           c.KeyID,
		SdcEndpoint:        auth.Endpoint{URL: c.Endpoint},
	}

	return cloudapi.New(client.NewClient(
		c.Endpoint,
		cloudapi.DefaultAPIVersion,
		creds,
		log.New(os.Stdout, "", log.Flags()),
	)), nil
}
开发者ID:joyent,项目名称:packer-builder-triton,代码行数:26,代码来源:access_config.go


示例10: CreateSDCClient

// CreateSDCClient returns an SDC client configured with the appropriate client credentials
// or an error if creating the client fails.
func (c *AccessConfig) CreateSDCClient() (*cloudapi.Client, error) {
	keyData, err := ioutil.ReadFile(c.KeyPath)
	if err != nil {
		return nil, err
	}

	userauth, err := auth.NewAuth(c.Account, string(keyData), "rsa-sha256")
	if err != nil {
		return nil, err
	}

	creds := &auth.Credentials{
		UserAuthentication: userauth,
		SdcKeyId:           c.KeyID,
		SdcEndpoint:        auth.Endpoint{URL: c.Endpoint},
	}

	return cloudapi.New(client.NewClient(
		c.Endpoint,
		cloudapi.DefaultAPIVersion,
		creds,
		&cloudapi.Logger,
	)), nil
}
开发者ID:jen20,项目名称:packer-builder-triton,代码行数:26,代码来源:access_config.go


示例11: SetUpTest

func (s *LiveTests) SetUpTest(c *gc.C) {
	client := client.NewClient(s.creds.MantaEndpoint.URL, "", s.creds, log.New(os.Stderr, "", log.LstdFlags))
	c.Assert(client, gc.NotNil)
	s.testClient = manta.New(client)
	c.Assert(s.testClient, gc.NotNil)
}
开发者ID:joyent,项目名称:gomanta,代码行数:6,代码来源:live_test.go


示例12: TestNewClient

func (s *ClientSuite) TestNewClient(c *gc.C) {
	cl := client.NewClient(s.creds.SdcEndpoint.URL, "", s.creds, nil)
	c.Assert(cl, gc.NotNil)
}
开发者ID:asteris-llc,项目名称:gocommon,代码行数:4,代码来源:client_test.go


示例13: SetUpTest

func (s *LiveTests) SetUpTest(c *gc.C) {
	client := client.NewClient(s.creds.MantaEndpoint.URL, "", s.creds, &manta.Logger)
	c.Assert(client, gc.NotNil)
	s.testClient = manta.New(client)
	c.Assert(s.testClient, gc.NotNil)
}
开发者ID:richardiux,项目名称:gomanta,代码行数:6,代码来源:live_test.go


示例14: SetUpTest

func (s *LocalTests) SetUpTest(c *gc.C) {
	client := client.NewClient(s.creds.SdcEndpoint.URL, cloudapi.DefaultAPIVersion, s.creds, log.New(os.Stderr, "", log.LstdFlags))
	c.Assert(client, gc.NotNil)
	s.testClient = cloudapi.New(client)
	c.Assert(s.testClient, gc.NotNil)
}
开发者ID:joyent,项目名称:gosdc,代码行数:6,代码来源:local_test.go


示例15: SetUpTest

func (s *LiveTests) SetUpTest(c *gc.C) {
	client := client.NewClient(s.creds.SdcEndpoint.URL, cloudapi.DefaultAPIVersion, s.creds, &cloudapi.Logger)
	c.Assert(client, gc.NotNil)
	s.testClient = cloudapi.New(client)
	c.Assert(s.testClient, gc.NotNil)
}
开发者ID:cehoffman,项目名称:gosdc,代码行数:6,代码来源:live_test.go


示例16: credentials

const unauthorisedMessage = `
Please ensure the Manta username and SSH access key you have
specified are correct. You can create or import an SSH key via
the "Account Summary" page in the Joyent console.`

// verifyCredentials issues a cheap, non-modifying request to Joyent to
// verify the configured credentials. If verification fails, a user-friendly
// error will be returned, and the original error will be logged at debug
// level.
var verifyCredentials = func(e *joyentEnviron) error {
	creds, err := credentials(e.Ecfg())
	if err != nil {
		return err
	}
	httpClient := client.NewClient(e.Ecfg().sdcUrl(), cloudapi.DefaultAPIVersion, creds, nil)
	apiClient := cloudapi.New(httpClient)
	_, err = apiClient.CountMachines()
	if err != nil {
		logger.Debugf("joyent request failed: %v", err)
		if joyenterrors.IsInvalidCredentials(err) || joyenterrors.IsNotAuthorized(err) {
			return errors.New("authentication failed.\n" + unauthorisedMessage)
		}
		return err
	}
	return nil
}

func credentials(cfg *environConfig) (*auth.Credentials, error) {
	authentication, err := auth.NewAuth(cfg.mantaUser(), cfg.privateKey(), cfg.algorithm())
	if err != nil {
开发者ID:imoapps,项目名称:juju,代码行数:30,代码来源:provider.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang errors.Newf函数代码示例发布时间:2022-05-23
下一篇:
Golang gcode.Block类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap