| 1234567891011121314151617181920212223242526272829303132333435 |
- // utils/http_client.go
- package utils
- import (
- "context"
- "time"
- "net/http"
- )
- type HTTPClient interface {
- PostJSON(ctx context.Context, url string, body interface{}) ([]byte, error)
- }
- type httpClient struct {
- client *http.Client
- }
- func NewHttpClient(timeout time.Duration) HTTPClient {
- return &httpClient{
- client: &http.Client{
- Timeout: timeout,
- Transport: &http.Transport{
- MaxIdleConns: 100,
- IdleConnTimeout: 90 * time.Second,
- DisableCompression: true,
- },
- },
- }
- }
- func (c *httpClient) PostJSON(ctx context.Context, url string, body interface{}) ([]byte, error) {
- // 实现具体的HTTP请求逻辑
- // 示例:返回空响应
- return []byte("{}"), nil
- }
|