Skip to content

Commit

Permalink
CDN SDK变更
Browse files Browse the repository at this point in the history
  • Loading branch information
李智春 authored and guozhifeng-felton committed Nov 24, 2022
1 parent 46c6577 commit e1c0f5a
Show file tree
Hide file tree
Showing 26 changed files with 1,514 additions and 748 deletions.
5 changes: 5 additions & 0 deletions base/client.go
Expand Up @@ -343,6 +343,11 @@ func (client *Client) request(ctx context.Context, api string, query url.Values,
req.Header.Set("Content-Type", ct)
}

if req.UserAgent() == "" {
req.Header.Set("User-Agent", strings.Join([]string{"volc-sdk-golang", client.SdkVersion}, "/"))
fmt.Println(req.UserAgent())
}

var resp []byte
var code int

Expand Down
26 changes: 26 additions & 0 deletions example/cdn/add_cdn_certificate.go
@@ -0,0 +1,26 @@
package cdn

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
)

func AddCdnCertificate(t *testing.T) {
resp, err := DefaultInstance.AddCdnCertificate(&cdn.AddCdnCertificateRequest{
Certificate: cdn.Certificate{
Certificate: cdn.GetStrPtr("-----BEGIN CERTIFICATE-----\\r\\nHmU2w=\\r\\n-----END CERTIFICATE-----\\r\\n-----BEGIN CERTIFICATE-----\\r\\nMIIElg==\\r\\n-----END CERTIFICATE-----\\r\\n-----BEGIN CERTIFICATE-----\\r\\nMIIDV5Adg\\r\\n06O/nVsJ8dWd4=\\r\\n-----END CERTIFICATE-----"),
PrivateKey: cdn.GetStrPtr("-----BEGIN RSA PRIVATE KEY-----\nMIIE6\nBNtw==\n-----END RSA PRIVATE KEY-----"),
},
CertInfo: &cdn.AddCdnCertInfo{
Desc: cdn.GetStrPtr("MyCert"),
},
Source: cdn.GetStrPtr("volc_cert_center"),
})

assert.NoError(t, err)
assert.NotNil(t, resp)
fmt.Printf("%+v", resp)
}
19 changes: 10 additions & 9 deletions example/cdn/add_cdn_domain.go
@@ -1,25 +1,26 @@
package cdn

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
"testing"
)

func AddCdnDomain(t *testing.T) {
resp, err := DefaultInstance.AddCdnDomain(&cdn.AddCdnDomainRequest{
Domain: operateDomain,
ServiceType: "web",
ServiceType: cdn.GetStrPtr("web"),
Origin: []cdn.OriginRule{
{OriginAction: cdn.OriginAction{
{OriginAction: &cdn.OriginAction{
OriginLines: []cdn.OriginLine{
{
OriginType: "primary",
InstanceType: "domain",
Address: "origin.test.com",
HttpPort: "80",
HttpsPort: "80",
Weight: "100",
OriginType: cdn.GetStrPtr("primary"),
InstanceType: cdn.GetStrPtr("ip"),
Address: cdn.GetStrPtr("1.1.1.1"),
HttpPort: cdn.GetStrPtr("80"),
HttpsPort: cdn.GetStrPtr("80"),
Weight: cdn.GetStrPtr("100"),
},
},
}},
Expand Down
7 changes: 4 additions & 3 deletions example/cdn/add_resource_tags.go
@@ -1,16 +1,17 @@
package cdn

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
"testing"
)

func AddResourceTags(t *testing.T) {
resp, err := DefaultInstance.AddResourceTags(&cdn.AddResourceTagsRequest{
Resources: []string{exampleDomain},
ResourceTags: []cdn.ResourceTagEntry{
{Key: "userKey", Value: "userValue"},
ResourceTags: []cdn.ResourceTag{
{Key: cdn.GetStrPtr("userKey"), Value: cdn.GetStrPtr("userValue")},
},
})
assert.NoError(t, err)
Expand Down
18 changes: 18 additions & 0 deletions example/cdn/batch_deploy_cert.go
@@ -0,0 +1,18 @@
package cdn

import (
"fmt"
"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
"testing"
)

func BatchDeployCert(t *testing.T) {
resp, err := DefaultInstance.BatchDeployCert(&cdn.BatchDeployCertRequest{
CertId: "cert-c195f679cecb4fc5yjt3dd8c54e6c0a2",
Domain: "www.example.com,img.example.com",
})
assert.NoError(t, err)
assert.NotNil(t, resp)
fmt.Printf("%+v", resp)
}
7 changes: 4 additions & 3 deletions example/cdn/delete_resource_tags.go
@@ -1,16 +1,17 @@
package cdn

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
"testing"
)

func DeleteResourceTags(t *testing.T) {
resp, err := DefaultInstance.DeleteResourceTags(&cdn.DeleteResourceTagsRequest{
Resources: []string{exampleDomain},
ResourceTags: []cdn.ResourceTagEntry{
{Key: "userKey", Value: "userValue"},
ResourceTags: []cdn.ResourceTag{
{Key: cdn.GetStrPtr("userKey"), Value: cdn.GetStrPtr("userValue")},
},
})
assert.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion example/cdn/describe_cdn_access_log.go
@@ -1,9 +1,10 @@
package cdn

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
"testing"
)

func DescribeCdnAccessLog(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions example/cdn/describe_cdn_data_detail.go
@@ -1,9 +1,10 @@
package cdn

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
"testing"
)

func DescribeCdnDataDetail(t *testing.T) {
Expand All @@ -15,6 +16,6 @@ func DescribeCdnDataDetail(t *testing.T) {
})
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.NotEmpty(t, resp.Result.Domain)
assert.NotEmpty(t, resp.Result.Name)
assert.NotEmpty(t, resp.Result.DataDetails)
}
18 changes: 18 additions & 0 deletions example/cdn/describe_cert_config.go
@@ -0,0 +1,18 @@
package cdn

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
)

func DescribeCertConfig(t *testing.T) {
resp, err := DefaultInstance.DescribeCertConfig(&cdn.DescribeCertConfigRequest{
CertId: cdn.GetStrPtr("cert-2b12dd79c3ef441ea1e58a09248d0fd6"),
})
assert.NoError(t, err)
assert.NotNil(t, resp)
fmt.Printf("%+v", resp)
}
7 changes: 4 additions & 3 deletions example/cdn/describe_content_block_tasks.go
@@ -1,16 +1,17 @@
package cdn

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
"testing"
)

func DescribeContentBlockTasks(t *testing.T) {
resp, err := DefaultInstance.DescribeContentBlockTasks(&cdn.DescribeContentBlockTasksRequest{
TaskType: "block_url",
StartTime: testStartTime,
EndTime: testEndTime,
StartTime: &testStartTime,
EndTime: &testEndTime,
})
assert.NoError(t, err)
assert.NotEmpty(t, resp.Result.Data)
Expand Down
3 changes: 2 additions & 1 deletion example/cdn/describe_content_quota.go
@@ -1,8 +1,9 @@
package cdn

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func DescribeContentQuota(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions example/cdn/describe_content_tasks.go
@@ -1,16 +1,17 @@
package cdn

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
"testing"
)

func DescribeContentTasks(t *testing.T) {
resp, err := DefaultInstance.DescribeContentTasks(&cdn.DescribeContentTasksRequest{
TaskType: "refresh_file",
StartTime: testStartTime,
EndTime: testEndTime,
StartTime: &testStartTime,
EndTime: &testEndTime,
})
assert.NoError(t, err)
assert.Greater(t, int(resp.Result.Total), 0)
Expand Down
5 changes: 3 additions & 2 deletions example/cdn/describe_edge_statistical_data.go
@@ -1,17 +1,18 @@
package cdn

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
"testing"
)

func DescribeEdgeStatisticalData(t *testing.T) {
resp, err := DefaultInstance.DescribeEdgeStatisticalData(&cdn.DescribeEdgeStatisticalDataRequest{
StartTime: testStartTime,
EndTime: testEndTime,
Metric: "clientIp",
Domain: exampleDomain,
Domain: &exampleDomain,
})
assert.NoError(t, err)
assert.NotNil(t, resp)
Expand Down
5 changes: 3 additions & 2 deletions example/cdn/describe_edge_top_statistical_data.go
@@ -1,17 +1,18 @@
package cdn

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
"testing"
)

func DescribeEdgeTopStatisticalData(t *testing.T) {
metric := "flux"
resp, err := DefaultInstance.DescribeEdgeTopStatisticalData(&cdn.DescribeEdgeTopStatisticalDataRequest{
StartTime: testStartTime,
EndTime: testEndTime,
Metric: &metric,
Metric: metric,
Domain: exampleDomain,
Item: "url",
})
Expand Down
10 changes: 7 additions & 3 deletions example/cdn/describe_ip_info.go
@@ -1,15 +1,19 @@
package cdn

import (
"encoding/json"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
"testing"
)

func DescribeIPInfo(t *testing.T) {
resp, err := DefaultInstance.DescribeIPInfo(&cdn.DescribeIPInfoRequest{
IP: exampleDomain,
IP: "1.1.1.1",
})
assert.NoError(t, err)
assert.Equal(t, exampleDomain, resp.Result.IP)
rsp, _ := json.Marshal(resp)
fmt.Printf("%+v", string(rsp))
}
14 changes: 14 additions & 0 deletions example/cdn/list_cdn_cert_info.go
@@ -0,0 +1,14 @@
package cdn

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)

func ListCdnCertInfo(t *testing.T) {
resp, err := DefaultInstance.ListCdnCertInfo(nil)
assert.NoError(t, err)
assert.NotNil(t, resp)
fmt.Printf("%+v", resp)
}
19 changes: 19 additions & 0 deletions example/cdn/list_cert_info.go
@@ -0,0 +1,19 @@
package cdn

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
)

func ListCertInfo(t *testing.T) {
resp, err := DefaultInstance.ListCertInfo(&cdn.ListCertInfoRequest{
Source: cdn.GetStrPtr("volc_cert_center"),
})

assert.NoError(t, err)
assert.NotNil(t, resp)
fmt.Printf("%+v", resp)
}
19 changes: 10 additions & 9 deletions example/cdn/update_cdn_config.go
@@ -1,24 +1,25 @@
package cdn

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
"testing"
)

func UpdateCdnConfig(t *testing.T) {
resp, err := DefaultInstance.UpdateCdnConfig(&cdn.UpdateCdnConfigRequest{
Domain: exampleDomain,
Domain: &exampleDomain,
Origin: []cdn.OriginRule{
{OriginAction: cdn.OriginAction{
{OriginAction: &cdn.OriginAction{
OriginLines: []cdn.OriginLine{
{
OriginType: "primary",
InstanceType: "domain",
Address: "new-origin.com",
HttpPort: "80",
HttpsPort: "80",
Weight: "100",
OriginType: cdn.GetStrPtr("primary"),
InstanceType: cdn.GetStrPtr("ip"),
Address: cdn.GetStrPtr("1.1.1.1"),
HttpPort: cdn.GetStrPtr("80"),
HttpsPort: cdn.GetStrPtr("80"),
Weight: cdn.GetStrPtr("100"),
},
},
}},
Expand Down
7 changes: 4 additions & 3 deletions example/cdn/update_resource_tags.go
@@ -1,16 +1,17 @@
package cdn

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/volcengine/volc-sdk-golang/service/cdn"
"testing"
)

func UpdateResourceTags(t *testing.T) {
resp, err := DefaultInstance.UpdateResourceTags(&cdn.UpdateResourceTagsRequest{
Resources: []string{exampleDomain},
ResourceTags: []cdn.ResourceTagEntry{
{Key: "userKey", Value: "userValue"},
ResourceTags: []cdn.ResourceTag{
{Key: cdn.GetStrPtr("userKey"), Value: cdn.GetStrPtr("userValue")},
},
})
assert.NoError(t, err)
Expand Down

0 comments on commit e1c0f5a

Please sign in to comment.