Skip to content

Commit d90cdfb

Browse files
author
Tíghearnán Carroll
committed
add hosted path support to lib
1 parent bf26a31 commit d90cdfb

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

channel.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import (
1010
"path"
1111
)
1212

13-
func (c *Client) getChanelBaseEndpoint() string {
13+
func (c *Client) getChannelBaseEndpoint() string {
1414
u := url.URL{
1515
Scheme: c.cfg.httpScheme(),
1616
Host: c.cfg.baseURL,
17-
Path: path.Join("/api", c.cfg.version, "/account"),
17+
Path: path.Join(c.cfg.path, "/api", c.cfg.version, "/account"),
1818
}
1919
return u.String()
2020
}
2121

2222
func (c *Client) getTokenBaseEndpoint(accountid int64, channelid string) string {
23-
return fmt.Sprintf("%s/%d/channel/%s/api-token", c.getChanelBaseEndpoint(), accountid, channelid)
23+
return fmt.Sprintf("%s/%d/channel/%s/api-token", c.getChannelBaseEndpoint(), accountid, channelid)
2424
}
2525

2626
// ChannelsRequest hold data for get channels request for a particular account
@@ -213,7 +213,7 @@ func (c *Client) Channels(ctx context.Context, r ChannelsRequest) (*ChannelsRepl
213213
req, err := http.NewRequestWithContext(
214214
ctx,
215215
http.MethodGet,
216-
fmt.Sprintf("%s/%d/channel/list", c.getChanelBaseEndpoint(), r.AccountID),
216+
fmt.Sprintf("%s/%d/channel/list", c.getChannelBaseEndpoint(), r.AccountID),
217217
nil,
218218
)
219219
if err != nil {
@@ -233,7 +233,7 @@ func (c *Client) Channel(ctx context.Context, r ChannelRequest) (*ChannelReply,
233233
req, err := http.NewRequestWithContext(
234234
ctx,
235235
http.MethodGet,
236-
fmt.Sprintf("%s/%d/channel/%s", c.getChanelBaseEndpoint(), r.AccountID, r.ChannelID),
236+
fmt.Sprintf("%s/%d/channel/%s", c.getChannelBaseEndpoint(), r.AccountID, r.ChannelID),
237237
nil,
238238
)
239239

@@ -259,7 +259,7 @@ func (c *Client) ChannelUpdate(ctx context.Context, r ChannelUpdateRequest) (*Ch
259259
req, err := http.NewRequestWithContext(
260260
ctx,
261261
http.MethodPost,
262-
fmt.Sprintf("%s/%d/channel/%s", c.getChanelBaseEndpoint(), r.AccountID, r.ChannelID),
262+
fmt.Sprintf("%s/%d/channel/%s", c.getChannelBaseEndpoint(), r.AccountID, r.ChannelID),
263263
bytes.NewBuffer(payload),
264264
)
265265

@@ -280,7 +280,7 @@ func (c *Client) ChannelDelete(ctx context.Context, r ChannelDeleteRequest) erro
280280
req, err := http.NewRequestWithContext(
281281
ctx,
282282
http.MethodDelete,
283-
fmt.Sprintf("%s/%d/channel/%s", c.getChanelBaseEndpoint(), r.AccountID, r.ChannelID),
283+
fmt.Sprintf("%s/%d/channel/%s", c.getChannelBaseEndpoint(), r.AccountID, r.ChannelID),
284284
nil,
285285
)
286286

@@ -301,7 +301,7 @@ func (c *Client) ChannelCreate(ctx context.Context, r ChannelCreateRequest) (*Ch
301301
req, err := http.NewRequestWithContext(
302302
ctx,
303303
http.MethodPost,
304-
fmt.Sprintf("%s/%d/channel", c.getChanelBaseEndpoint(), r.AccountID),
304+
fmt.Sprintf("%s/%d/channel", c.getChannelBaseEndpoint(), r.AccountID),
305305
bytes.NewBuffer(payload),
306306
)
307307

client.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type spvConfig struct {
7171
insecure bool // equivalent curl -k
7272
tls bool
7373
baseURL string
74+
path string
7475
version string
7576
user string
7677
passwd string
@@ -118,6 +119,13 @@ func WithBaseURL(url string) SPVConfigFunc {
118119
}
119120
}
120121

122+
// WithPath provide a path on the hosting service (/peerchannels)
123+
func WithPath(path string) SPVConfigFunc {
124+
return func(c *spvConfig) {
125+
c.path = path
126+
}
127+
}
128+
121129
// WithVersion provide version string for the rest api
122130
func WithVersion(v string) SPVConfigFunc {
123131
return func(c *spvConfig) {
@@ -399,7 +407,7 @@ func NewWSClient(opts ...SPVConfigFunc) (*WSClient, error) {
399407

400408
// urlPath return the path part of the connection URL
401409
func (c *WSClient) urlPath() string {
402-
return path.Join("/api", c.cfg.version, "/channel", c.cfg.channelID, "/notify")
410+
return path.Join(c.cfg.path, "/api", c.cfg.version, "/channel", c.cfg.channelID, "/notify")
403411
}
404412

405413
// connectServer establish the connection to the server
@@ -454,7 +462,6 @@ func (c *WSClient) Close() {
454462
// Run establishes the connection and start listening the notification stream
455463
// process the notification if a callback is provided
456464
func (c *WSClient) Run() {
457-
458465
go func() {
459466
defer func() {
460467
_ = recover()

message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func (c *Client) getMessageBaseEndpoint() string {
1313
u := url.URL{
1414
Scheme: c.cfg.httpScheme(),
1515
Host: c.cfg.baseURL,
16-
Path: path.Join("/api", c.cfg.version),
16+
Path: path.Join(c.cfg.path, "/api", c.cfg.version),
1717
}
1818
return u.String()
1919
}

0 commit comments

Comments
 (0)