Skip to content

Commit

Permalink
Use url.JoinPath to consume -server argument without string mashi…
Browse files Browse the repository at this point in the history
…ng (#14)
  • Loading branch information
jasikpark authored Jun 11, 2024
1 parent 391c978 commit 4589547
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"net"
"net/http"
"net/url"
"sync/atomic"
"time"

Expand Down Expand Up @@ -111,8 +112,11 @@ func (c *Client) Enroll(ctx context.Context, logger logrus.FieldLogger, code str
if err != nil {
return nil, nil, nil, nil, err
}

req, err := http.NewRequestWithContext(ctx, "POST", c.dnServer+message.EnrollEndpoint, bytes.NewBuffer(jv))
enrollURL, err := url.JoinPath(c.dnServer, message.EnrollEndpoint)
if err != nil {
return nil, nil, nil, nil, err
}
req, err := http.NewRequestWithContext(ctx, "POST", enrollURL, bytes.NewBuffer(jv))
if err != nil {
return nil, nil, nil, nil, err
}
Expand Down Expand Up @@ -315,7 +319,11 @@ func (c *Client) streamingPostDNClient(ctx context.Context, reqType string, valu
}
pbb := bytes.NewBuffer(postBody)

req, err := http.NewRequestWithContext(ctx, "POST", c.dnServer+message.EndpointV1, io.MultiReader(pbb, pr))
endpointV1URL, err := url.JoinPath(c.dnServer, message.EndpointV1)
if err != nil {
return nil, err
}
req, err := http.NewRequestWithContext(ctx, "POST", endpointV1URL, io.MultiReader(pbb, pr))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -365,7 +373,11 @@ func (c *Client) postDNClient(ctx context.Context, reqType string, value []byte,
return nil, err
}

req, err := http.NewRequestWithContext(ctx, "POST", c.dnServer+message.EndpointV1, bytes.NewReader(postBody))
endpointV1URL, err := url.JoinPath(c.dnServer, message.EndpointV1)
if err != nil {
return nil, err
}
req, err := http.NewRequestWithContext(ctx, "POST", endpointV1URL, bytes.NewReader(postBody))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 4589547

Please sign in to comment.