feat: add customer portal and RTC voice diagnostics
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
volcbase "github.com/volcengine/volc-sdk-golang/base"
|
||||
)
|
||||
|
||||
func main() {
|
||||
akFile := flag.String("ak-file", "", "file containing the Volcengine AccessKey ID")
|
||||
skFile := flag.String("sk-file", "", "file containing the Volcengine SecretAccessKey")
|
||||
resourceID := flag.String("resource-id", "volc.speech.dialog", "speech service resource ID")
|
||||
projectName := flag.String("project", "default", "Volcengine project name")
|
||||
flag.Parse()
|
||||
if *akFile == "" || *skFile == "" {
|
||||
panic("-ak-file and -sk-file are required")
|
||||
}
|
||||
target, _ := url.Parse("https://open.volcengineapi.com")
|
||||
query := target.Query()
|
||||
query.Set("Action", "QuotaMonitoring")
|
||||
query.Set("Version", "2025-05-21")
|
||||
target.RawQuery = query.Encode()
|
||||
today := time.Now().Format("2006-01-02")
|
||||
body, _ := json.Marshal(map[string]any{
|
||||
"ProjectName": *projectName,
|
||||
"ResourceID": *resourceID,
|
||||
"Start": today,
|
||||
"End": today,
|
||||
"Mode": "daily",
|
||||
"QuotaType": "concurrency",
|
||||
})
|
||||
request, _ := http.NewRequest(http.MethodPost, target.String(), bytes.NewReader(body))
|
||||
request.Host = target.Host
|
||||
request.Header.Set("Content-Type", "application/json; charset=UTF-8")
|
||||
credentials := volcbase.Credentials{
|
||||
AccessKeyID: readSecret(*akFile), SecretAccessKey: readSecret(*skFile),
|
||||
Service: "speech_saas_prod", Region: "cn-beijing",
|
||||
}
|
||||
credentials.Sign(request)
|
||||
response, err := (&http.Client{Timeout: 15 * time.Second}).Do(request)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer response.Body.Close()
|
||||
responseBody, _ := io.ReadAll(io.LimitReader(response.Body, 1<<20))
|
||||
var decoded map[string]any
|
||||
_ = json.Unmarshal(responseBody, &decoded)
|
||||
encoded, _ := json.Marshal(decoded)
|
||||
fmt.Printf("status=%d response=%s\n", response.StatusCode, encoded)
|
||||
}
|
||||
|
||||
func readSecret(path string) string {
|
||||
value, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return strings.TrimSpace(string(value))
|
||||
}
|
||||
Reference in New Issue
Block a user