package client import ( "bytes" "context" "errors" "io" "net/http" "strings" "time" ) type Client struct { BaseURL string; HTTP *http.Client } func (c Client) Post(ctx context.Context, path string, body []byte, walletKey string) ([]byte,error) { if !strings.HasPrefix(path,"/api/v5/btc/") { return nil, errors.New("path not allowed") } if strings.TrimSpace(c.BaseURL)=="" {return nil,errors.New("missing base URL")} req,err:=http.NewRequestWithContext(ctx,http.MethodPost,strings.TrimRight(c.BaseURL,"/")+path,bytes.NewReader(body));if err!=nil{return nil,err} req.Header.Set("Content-Type","application/json") if walletKey!="" {req.Header.Set("X-BTC-KEY",walletKey)} h:=c.HTTP;if h==nil{h=&http.Client{Timeout:10*time.Second}} resp,err:=h.Do(req);if err!=nil{return nil,err};defer resp.Body.Close() raw,err:=io.ReadAll(io.LimitReader(resp.Body,1<<20));if err!=nil{return nil,err} if resp.StatusCode<200||resp.StatusCode>=300{return nil,errors.New("engine HTTP error")} return raw,nil }