| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 | package gnetimport (	"bytes"	"encoding/json"	"errors"	"net/http"	"time")const (	HTTPContentTypeJson = "application/json; charset=utf-8")var (	httpGlobalClient = &http.Client{		Timeout: 2 * time.Second,		Transport: &http.Transport{			Proxy:               nil,			MaxIdleConns:        1,               // 最大空闲连接数			MaxIdleConnsPerHost: 1,               // 每个主机最大空闲连接数			IdleConnTimeout:     5 * time.Second, // 空闲连接超时时间		},	})func PostJson(uri string, r []byte, v any) error {	resp, err := httpGlobalClient.Post(uri, HTTPContentTypeJson, bytes.NewBuffer(r))	if err != nil {		return err	}	defer func() {		_ = resp.Body.Close()	}()	if resp.StatusCode != http.StatusOK {		return errors.New(resp.Status)	}	return json.NewDecoder(resp.Body).Decode(v)}func GetJson(uri string, v any) error {	resp, err := httpGlobalClient.Get(uri)	if err != nil {		return err	}	defer func() {		_ = resp.Body.Close()	}()	if resp.StatusCode != http.StatusOK {		return errors.New(resp.Status)	}	return json.NewDecoder(resp.Body).Decode(v)}
 |