feat cn client支持tls

This commit is contained in:
timerzz 2024-06-14 17:42:07 +08:00
parent 77e0c69168
commit 8ba5c95a9c
2 changed files with 11 additions and 4 deletions

View File

@ -2,9 +2,11 @@ package coach_client
import (
"context"
"crypto/tls"
"fmt"
"github.com/bytedance/sonic"
"github.com/cloudwego/hertz/pkg/app/client"
"github.com/cloudwego/hertz/pkg/network/standard"
"github.com/cloudwego/hertz/pkg/protocol"
"github.com/corpix/uarand"
"time"
@ -16,7 +18,13 @@ type CN struct {
func CNClient() (cli *CN, err error) {
cli = new(CN)
cli.c, err = client.NewClient()
clientCfg := &tls.Config{
InsecureSkipVerify: true,
}
cli.c, err = client.NewClient(
client.WithTLSConfig(clientCfg),
client.WithDialer(standard.NewDialer()),
)
return
}

View File

@ -10,14 +10,13 @@ func TestCNClient(t *testing.T) {
if err != nil {
t.Fatal(err)
}
var page, total int
var page int
var resp ItemListData
var items []CNItem
for ; page <= total; page++ {
for ; page < 2; page++ {
if resp, err = cli.ListItems(context.Background(), page, 50); err != nil {
t.Fatal(err)
}
total = resp.TotalPages
items = append(items, resp.Items...)
}
t.Logf("共%d个", len(items))