本文整理汇总了Golang中github.com/digitalocean/godo.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: VerifyCredential
// VerifyCredential verifies whether the users DO credentials (access token) is
// valid or not
func (s *Stack) VerifyCredential(c *stack.Credential) error {
cred := c.Credential.(*Credential)
if err := cred.Valid(); err != nil {
return err
}
oauthClient := oauth2.NewClient(
oauth2.NoContext,
oauth2.StaticTokenSource(&oauth2.Token{AccessToken: cred.AccessToken}),
)
client := godo.NewClient(oauthClient)
// let's retrieve our Account information. If it's successful, we're good
// to go
_, _, err := client.Account.Get()
if err != nil {
return &stack.Error{
Err: err,
}
}
return nil
}
示例2: GetClient
func GetClient() *godo.Client {
token := &oauth2.Token{AccessToken: token}
t := oauth2.StaticTokenSource(token)
oauthClient := oauth2.NewClient(oauth2.NoContext, t)
return godo.NewClient(oauthClient)
}
示例3: getClient
func (d *Driver) getClient() *godo.Client {
token := &oauth2.Token{AccessToken: d.AccessToken}
tokenSource := oauth2.StaticTokenSource(token)
client := oauth2.NewClient(oauth2.NoContext, tokenSource)
return godo.NewClient(client)
}
示例4: GetClient
// GetClient returns a godo client.
func GetClient(token string) *godo.Client {
tokenSource := &TokenSource{AccessToken: token}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
client.BaseURL = GodoBase
return client
}
示例5: New
// New returns a new instance of DoImages
func New(conf *DoConfig) (*DoImages, error) {
if conf.Token == "" {
return nil, errors.New("Access Token is not set. Please check your configuration.")
}
// increase the timeout
timeout := time.Second * 30
client := &http.Client{
Transport: &http.Transport{TLSHandshakeTimeout: timeout},
Timeout: timeout,
}
// we need to pass the client with the context itself
ctx := context.WithValue(oauth2.NoContext, oauth2.HTTPClient, client)
oauthClient := oauth2.NewClient(ctx, &tokenSource{
AccessToken: conf.Token,
})
godoClient := godo.NewClient(oauthClient)
return &DoImages{
client: godoClient,
images: make([]godo.Image, 0),
}, nil
}
示例6: getClient
func (d *Driver) getClient() *godo.Client {
t := &oauth.Transport{
Token: &oauth.Token{AccessToken: d.AccessToken},
}
return godo.NewClient(t.Client())
}
示例7: clientFromToken
func clientFromToken(pat string) *godo.Client {
tokenSrc := &tokenSource{
AccessToken: pat,
}
return godo.NewClient(oauth2.NewClient(oauth2.NoContext, tokenSrc))
}
示例8: loadDoClient
func loadDoClient() {
tokenSource := &TokenSource{
AccessToken: globalConfig.APIToken,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
doClient = godo.NewClient(oauthClient)
}
示例9: GetClientHandle
func (dm *DoDropletMarshaller) GetClientHandle(token string) *godo.Client {
tokenSource := &TokenSource{
AccessToken: token,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
return client
}
示例10: getClinet
func getClinet(accessToken string) *godo.Client {
t := &oauth.Transport{
Token: &oauth.Token{AccessToken: accessToken},
}
return godo.NewClient(t.Client())
}
示例11: NewDOClient
func NewDOClient(token string) *godo.Client {
tokenSource := &TokenSource{
AccessToken: token,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
return client
}
示例12: NewClient
// NewClient creates creates a godo.Client givent a token.
func (cs *LiveConfig) NewClient(token string) *godo.Client {
tokenSource := &TokenSource{
AccessToken: token,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
return godo.NewClient(oauthClient)
}
示例13: MakeDigitalOcean
func MakeDigitalOcean(token string) *DigitalOcean {
do := new(DigitalOcean)
tokenSource := &TokenSource{
AccessToken: token,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
do.client = godo.NewClient(oauthClient)
return do
}
示例14: getClient
func getClient(token string) *godo.Client {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
client := godo.NewClient(tc)
return client
}
示例15: withClient
func withClient(handler http.Handler, fn func(client *godo.Client) error) error {
server := httptest.NewServer(handler)
defer server.Close()
client := godo.NewClient(nil)
url, _ := url.Parse(server.URL)
client.BaseURL = url
return fn(client)
}