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 915 B

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

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