You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

client.go 1.1 kB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package api
  2. import (
  3. "crypto/ecdsa"
  4. "crypto/tls"
  5. "net/http"
  6. "gitlink.org.cn/cloudream/common/sdks"
  7. "gitlink.org.cn/cloudream/jcs-pub/client/internal/http/auth"
  8. "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
  9. "gitlink.org.cn/cloudream/jcs-pub/client/sdk/signer"
  10. "golang.org/x/net/http2"
  11. )
  12. type response[T any] struct {
  13. Code string `json:"code"`
  14. Message string `json:"message"`
  15. Data T `json:"data"`
  16. }
  17. func (r *response[T]) ToError() *sdks.CodeMessageError {
  18. return &sdks.CodeMessageError{
  19. Code: r.Code,
  20. Message: r.Message,
  21. }
  22. }
  23. type Client struct {
  24. cfg api.Config
  25. httpCli *http.Client
  26. signKey *signer.SignKey
  27. }
  28. func NewClient(cfg api.Config) *Client {
  29. httpCli := &http.Client{
  30. Transport: &http2.Transport{
  31. TLSClientConfig: &tls.Config{
  32. RootCAs: cfg.RootCA,
  33. Certificates: []tls.Certificate{cfg.Cert},
  34. ServerName: auth.ClientInternalSNI,
  35. NextProtos: []string{"h2"},
  36. },
  37. },
  38. }
  39. privKey := cfg.Cert.PrivateKey.(*ecdsa.PrivateKey)
  40. return &Client{
  41. cfg: cfg,
  42. httpCli: httpCli,
  43. signKey: signer.NewSignKey(privKey),
  44. }
  45. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。