Skip to content

Commit 6c43b9f

Browse files
author
wanjiewu
committed
支持查询播放key
1 parent 8e8268a commit 6c43b9f

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ cover.html
2929
cover.out
3030
covprofile
3131
coverage.html
32-
example/CI/media_process/media_process
32+
example/CI/media_process/test*
3333
.vscode

ci_media.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,40 @@ func (s *CIService) GetMediaInfo(ctx context.Context, name string, opt *ObjectGe
14211421
return &res, resp, err
14221422
}
14231423

1424+
type PlayKey struct {
1425+
MasterPlayKey string `xml:"MasterPlayKey"`
1426+
BackupPlayKey string `xml:"BackupPlayKey"`
1427+
}
1428+
1429+
type PlayKeyResult struct {
1430+
XMLName xml.Name `xml:"Response"`
1431+
PlayKeyList *PlayKey `xml:"PlayKeyList"`
1432+
}
1433+
1434+
func (s *CIService) CreatePlayKey(ctx context.Context) (*PlayKeyResult, *Response, error) {
1435+
var res PlayKeyResult
1436+
sendOpt := sendOptions{
1437+
baseURL: s.client.BaseURL.CIURL,
1438+
uri: "/playKey",
1439+
method: http.MethodPost,
1440+
result: &res,
1441+
}
1442+
resp, err := s.client.send(ctx, &sendOpt)
1443+
return &res, resp, err
1444+
}
1445+
1446+
func (s *CIService) GetPlayKey(ctx context.Context) (*PlayKeyResult, *Response, error) {
1447+
var res PlayKeyResult
1448+
sendOpt := sendOptions{
1449+
baseURL: s.client.BaseURL.CIURL,
1450+
uri: "/playKey",
1451+
method: http.MethodGet,
1452+
result: &res,
1453+
}
1454+
resp, err := s.client.send(ctx, &sendOpt)
1455+
return &res, resp, err
1456+
}
1457+
14241458
// GenerateMediaInfoOptions TODO
14251459
type GenerateMediaInfoOptions struct {
14261460
XMLName xml.Name `xml:"Request"`
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
"net/url"
8+
"os"
9+
10+
"github.com/tencentyun/cos-go-sdk-v5"
11+
"github.com/tencentyun/cos-go-sdk-v5/debug"
12+
)
13+
14+
func log_status(err error) {
15+
if err == nil {
16+
return
17+
}
18+
if cos.IsNotFoundError(err) {
19+
// WARN
20+
fmt.Println("WARN: Resource is not existed")
21+
} else if e, ok := cos.IsCOSError(err); ok {
22+
fmt.Printf("ERROR: Code: %v\n", e.Code)
23+
fmt.Printf("ERROR: Message: %v\n", e.Message)
24+
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
25+
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
26+
// ERROR
27+
} else {
28+
fmt.Printf("ERROR: %v\n", err)
29+
// ERROR
30+
}
31+
}
32+
33+
func getClient() *cos.Client {
34+
u, _ := url.Parse("https://testpic-1253960454.cos.ap-chongqing.myqcloud.com")
35+
cu, _ := url.Parse("https://testpic-1253960454.ci.ap-chongqing.myqcloud.com")
36+
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
37+
c := cos.NewClient(b, &http.Client{
38+
Transport: &cos.AuthorizationTransport{
39+
SecretID: os.Getenv("COS_SECRETID"),
40+
SecretKey: os.Getenv("COS_SECRETKEY"),
41+
Transport: &debug.DebugRequestTransport{
42+
RequestHeader: true,
43+
// Notice when put a large file and set need the request body, might happend out of memory error.
44+
RequestBody: true,
45+
ResponseHeader: true,
46+
ResponseBody: false,
47+
},
48+
},
49+
})
50+
return c
51+
}
52+
53+
func CreatePlayKey() {
54+
c := getClient()
55+
Res, _, err := c.CI.CreatePlayKey(context.Background())
56+
log_status(err)
57+
fmt.Printf("%+v\n", Res.PlayKeyList)
58+
}
59+
60+
func GetPlayKey() {
61+
c := getClient()
62+
63+
Res, _, err := c.CI.GetPlayKey(context.Background())
64+
log_status(err)
65+
fmt.Printf("%+v\n", Res.PlayKeyList)
66+
67+
}
68+
69+
func main() {
70+
CreatePlayKey()
71+
GetPlayKey()
72+
}

0 commit comments

Comments
 (0)