JCC-CSScheduler/common/pkgs/mq/executor/httpclient.go

54 lines
866 B
Go

package executor
import (
"gitlink.org.cn/cloudream/common/sdks"
)
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 HttpClient struct {
baseURL string
}
func NewHttpClient(cfg *Config) *HttpClient {
return &HttpClient{
baseURL: cfg.URL,
}
}
type HttpPool interface {
AcquireByUrl(url string) (*HttpClient, error)
//Release(cli *Client)
}
type httppool struct {
cfg *Config
}
func NewHttpPool(cfg *Config) HttpPool {
return &httppool{
cfg: cfg,
}
}
func (p *httppool) AcquireByUrl(url string) (*HttpClient, error) {
p.cfg.URL = url
cli := NewHttpClient(p.cfg)
return cli, nil
}
//func (p *pool) Release(cli *Client) {
//
//}