-
Notifications
You must be signed in to change notification settings - Fork 0
/
baidubce.go
42 lines (35 loc) · 842 Bytes
/
baidubce.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package baidu_gosdk
import (
"github.com/1cool/baidu-gosdk/imagerecognition"
"net/http"
"net/url"
"time"
)
type BaiduBce interface {
NewImageRecognition() imagerecognition.Service
setAccessToken(clientID, clientSecret string) error
}
type baiduBce struct {
accessToken url.Values
client *http.Client
}
func NewBaiduBce(clientID, clientSecret string) (BaiduBce, error) {
b := &baiduBce{
accessToken: url.Values{},
client: &http.Client{
Timeout: 30 * time.Second,
Transport: &http.Transport{
MaxIdleConnsPerHost: 30,
},
},
}
err := b.setAccessToken(clientID, clientSecret)
if err != nil {
return nil, err
}
return b, nil
}
var _ BaiduBce = (*baiduBce)(nil)
func (b *baiduBce) NewImageRecognition() imagerecognition.Service {
return imagerecognition.NewImageRecognition(b.accessToken, b.client)
}