1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-10-30 23:47:59 +02:00

perf(transport/http): optimize URL construction with url.URL for better performance (#3678)

Co-authored-by: huangzw <huangzw@2345.com>
Co-authored-by: Tony.Chen <zhihui_chen@foxmail.com>
This commit is contained in:
Name
2025-09-04 21:34:08 +08:00
committed by GitHub
parent 9f854e6981
commit 3e3318a458

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"time"
"github.com/go-kratos/kratos/v2/encoding"
@@ -226,8 +227,12 @@ func (client *Client) Invoke(ctx context.Context, method, path string, args any,
contentType = c.contentType
body = bytes.NewReader(data)
}
url := fmt.Sprintf("%s://%s%s", client.target.Scheme, client.target.Authority, path)
req, err := http.NewRequest(method, url, body)
u := url.URL{
Scheme: client.target.Scheme,
Host: client.target.Authority,
Path: path,
}
req, err := http.NewRequest(method, u.String(), body)
if err != nil {
return err
}