From 7f30199e6c1be4be8c3db39ff5704d9c5de08a90 Mon Sep 17 00:00:00 2001 From: y1nhui Date: Mon, 18 Aug 2025 13:40:46 +0800 Subject: [PATCH] refactor: replace string formatting with url.URL for endpoint URL construction --- endpoint.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/endpoint.go b/endpoint.go index 13e2dda..93fdcf3 100644 --- a/endpoint.go +++ b/endpoint.go @@ -1,7 +1,9 @@ package winrm import ( - "fmt" + "net" + "net/url" + "strconv" "time" ) @@ -37,7 +39,14 @@ func (ep *Endpoint) url() string { scheme = "http" } - return fmt.Sprintf("%s://%s:%d/wsman", scheme, ep.Host, ep.Port) + u := &url.URL{ + Scheme: scheme, + Host: net.JoinHostPort(ep.Host, strconv.Itoa(ep.Port)), + Path: "/wsman", + } + + return u.String() + } // NewEndpoint returns new pointer to struct Endpoint, with a default 60s response header timeout