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

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