package api import ( "crypto/ecdsa" "crypto/tls" "net/http" "gitlink.org.cn/cloudream/common/sdks" "gitlink.org.cn/cloudream/jcs-pub/client/internal/http/auth" "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api" "gitlink.org.cn/cloudream/jcs-pub/client/sdk/signer" "golang.org/x/net/http2" ) type response[T any] struct { Code string `json:"code"` Message string `json:"message"` Data T `json:"data"` } func (r *response[T]) ToError() *sdks.CodeMessageError { return &sdks.CodeMessageError{ Code: r.Code, Message: r.Message, } } type Client struct { cfg api.Config httpCli *http.Client signKey *signer.SignKey } func NewClient(cfg api.Config) *Client { httpCli := &http.Client{ Transport: &http2.Transport{ TLSClientConfig: &tls.Config{ RootCAs: cfg.RootCA, Certificates: []tls.Certificate{cfg.Cert}, ServerName: auth.ClientInternalSNI, NextProtos: []string{"h2"}, }, }, } privKey := cfg.Cert.PrivateKey.(*ecdsa.PrivateKey) return &Client{ cfg: cfg, httpCli: httpCli, signKey: signer.NewSignKey(privKey), } }