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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package stgsdk
  2. import "gitlink.org.cn/cloudream/common/sdks"
  3. type response[T any] struct {
  4. Code string `json:"code"`
  5. Message string `json:"message"`
  6. Data T `json:"data"`
  7. }
  8. func (r *response[T]) ToError() *sdks.CodeMessageError {
  9. return &sdks.CodeMessageError{
  10. Code: r.Code,
  11. Message: r.Message,
  12. }
  13. }
  14. type Client struct {
  15. baseURL string
  16. }
  17. func NewClient(cfg *Config) *Client {
  18. return &Client{
  19. baseURL: cfg.URL,
  20. }
  21. }
  22. type PoolClient struct {
  23. *Client
  24. owner *Pool
  25. }
  26. func (c *PoolClient) Close() {
  27. c.owner.Release(c)
  28. }
  29. type Pool struct {
  30. cfg *Config
  31. }
  32. func NewPool(cfg *Config) *Pool {
  33. return &Pool{
  34. cfg: cfg,
  35. }
  36. }
  37. func (p *Pool) Acquire() (*PoolClient, error) {
  38. cli := NewClient(p.cfg)
  39. return &PoolClient{
  40. Client: cli,
  41. owner: p,
  42. }, nil
  43. }
  44. func (p *Pool) Release(cli *PoolClient) {
  45. }