@@ -6,36 +6,39 @@ import (
66 "encoding/json"
77 "fmt"
88 "net/http"
9+ "net/url"
10+ "path"
911)
1012
1113func (c * Client ) getChanelBaseEndpoint () string {
12- return fmt .Sprintf ("https://%s/api/%s/account" , c .cfg .baseURL , c .cfg .version )
14+ u := url.URL {
15+ Scheme : c .cfg .httpScheme (),
16+ Host : c .cfg .baseURL ,
17+ Path : path .Join ("/api" , c .cfg .version , "/account" ),
18+ }
19+ return u .String ()
1320}
1421
15- func (c * Client ) getTokenBaseEndpoint (accountid , channelid string ) string {
16- return fmt .Sprintf ("%s/%s /channel/%s/api-token" , c .getChanelBaseEndpoint (), accountid , channelid )
22+ func (c * Client ) getTokenBaseEndpoint (accountid int64 , channelid string ) string {
23+ return fmt .Sprintf ("%s/%d /channel/%s/api-token" , c .getChanelBaseEndpoint (), accountid , channelid )
1724}
1825
1926// ChannelsRequest hold data for get channels request for a particular account
2027type ChannelsRequest struct {
21- AccountID string `json:"accountid"`
28+ AccountID int64 `json:"accountid"`
2229}
2330
2431// ChannelsReply hold data for get channels reply. It is a list of channel's detail
2532type ChannelsReply struct {
2633 Channels []struct {
27- ID string `json:"id"`
28- Href string `json:"href"`
29- PublicRead bool `json:"public_read"`
30- PublicWrite bool `json:"public_write"`
31- Sequenced bool `json:"sequenced"`
32- Locked bool `json:"locked"`
33- Head int `json:"head"`
34- Retention struct {
35- MinAgeDays int `json:"min_age_days"`
36- MaxAgeDays int `json:"max_age_days"`
37- AutoPrune bool `json:"auto_prune"`
38- } `json:"retention"`
34+ ID string `json:"id"`
35+ Href string `json:"href"`
36+ PublicRead bool `json:"public_read"`
37+ PublicWrite bool `json:"public_write"`
38+ Sequenced bool `json:"sequenced"`
39+ Locked bool `json:"locked"`
40+ Head int `json:"head"`
41+ Retention Retention `json:"retention"`
3942 AccessTokens []struct {
4043 ID string `json:"id"`
4144 Token string `json:"token"`
@@ -48,7 +51,7 @@ type ChannelsReply struct {
4851
4952// ChannelRequest hold data for get channel request
5053type ChannelRequest struct {
51- AccountID string `json:"accountid"`
54+ AccountID int64 `json:"accountid"`
5255 ChannelID string `json:"channelid"`
5356}
5457
@@ -80,7 +83,7 @@ type ChannelReply struct {
8083// And the properties values to be updated. These properties defines
8184// common permission for the channel
8285type ChannelUpdateRequest struct {
83- AccountID string `json:"accountid"`
86+ AccountID int64 `json:"accountid"`
8487 ChannelID string `json:"channelid"`
8588 PublicRead bool `json:"public_read"`
8689 PublicWrite bool `json:"public_write"`
@@ -98,42 +101,41 @@ type ChannelUpdateReply struct {
98101// ChannelDeleteRequest hold data for delete channel request
99102// The request contains the account and channel identification
100103type ChannelDeleteRequest struct {
101- AccountID string `json:"accountid"`
104+ AccountID int64 `json:"accountid"`
102105 ChannelID string `json:"channelid"`
103106}
104107
105108// ChannelCreateRequest hold data for create channel request
106109// The request should contain the account id, and optionally some
107110// channel properties to be initialised.
108111type ChannelCreateRequest struct {
109- AccountID string `json:"accountid"`
110- PublicRead bool `json:"public_read"`
111- PublicWrite bool `json:"public_write"`
112- Sequenced bool `json:"sequenced"`
113- Retention struct {
114- MinAgeDays int `json:"min_age_days"`
115- MaxAgeDays int `json:"max_age_days"`
116- AutoPrune bool `json:"auto_prune"`
117- } `json:"retention"`
112+ AccountID int64 `json:"accountid"`
113+ PublicRead bool `json:"public_read"`
114+ PublicWrite bool `json:"public_write"`
115+ Sequenced bool `json:"sequenced"`
116+ Retention Retention `json:"retention"`
117+ }
118+
119+ // Retention the data retention policy of a channel.
120+ type Retention struct {
121+ MinAgeDays int `json:"min_age_days"`
122+ MaxAgeDays int `json:"max_age_days"`
123+ AutoPrune bool `json:"auto_prune"`
118124}
119125
120126// ChannelCreateReply hold data for create channel reply
121127// It contains the new channel id, it's properties and the first
122128// default created token to allow authentification the communication
123129// on this channel
124130type ChannelCreateReply struct {
125- ID string `json:"id"`
126- Href string `json:"href"`
127- PublicRead bool `json:"public_read"`
128- PublicWrite bool `json:"public_write"`
129- Sequenced bool `json:"sequenced"`
130- Locked bool `json:"locked"`
131- Head int `json:"head"`
132- Retention struct {
133- MinAgeDays int `json:"min_age_days"`
134- MaxAgeDays int `json:"max_age_days"`
135- AutoPrune bool `json:"auto_prune"`
136- } `json:"retention"`
131+ ID string `json:"id"`
132+ Href string `json:"href"`
133+ PublicRead bool `json:"public_read"`
134+ PublicWrite bool `json:"public_write"`
135+ Sequenced bool `json:"sequenced"`
136+ Locked bool `json:"locked"`
137+ Head int `json:"head"`
138+ Retention Retention `json:"retention"`
137139 AccessTokens []struct {
138140 ID string `json:"id"`
139141 Token string `json:"token"`
@@ -147,7 +149,7 @@ type ChannelCreateReply struct {
147149// A token belong to a particular channel, which again belong to a particular account.
148150// To identify a token, it needs to provide account id, channel id, and token id
149151type TokenRequest struct {
150- AccountID string `json:"accountid"`
152+ AccountID int64 `json:"accountid"`
151153 ChannelID string `json:"channelid"`
152154 TokenID string `json:"tokenid"`
153155}
@@ -170,15 +172,15 @@ type TokenReply struct {
170172// A token belong to a particular channel, which again belong to a particular account.
171173// To identify a token, it needs to provide account id, channel id, and token id
172174type TokenDeleteRequest struct {
173- AccountID string `json:"accountid"`
175+ AccountID int64 `json:"accountid"`
174176 ChannelID string `json:"channelid"`
175177 TokenID string `json:"tokenid"`
176178}
177179
178180// TokensRequest hold data for get tokens request
179181// The request contains the account id and channel id.
180182type TokensRequest struct {
181- AccountID string `json:"accountid"`
183+ AccountID int64 `json:"accountid"`
182184 ChannelID string `json:"channelid"`
183185}
184186
@@ -189,7 +191,7 @@ type TokensReply []TokenReply
189191// The request should contains existing account and channel id,
190192// with optionally some description and permission properties attached to the token
191193type TokenCreateRequest struct {
192- AccountID string `json:"accountid"`
194+ AccountID int64 `json:"accountid"`
193195 ChannelID string `json:"channelid"`
194196 Description string `json:"description"`
195197 CanRead bool `json:"can_read"`
@@ -211,7 +213,7 @@ func (c *Client) Channels(ctx context.Context, r ChannelsRequest) (*ChannelsRepl
211213 req , err := http .NewRequestWithContext (
212214 ctx ,
213215 http .MethodGet ,
214- fmt .Sprintf ("%s/%s /channel/list" , c .getChanelBaseEndpoint (), r .AccountID ),
216+ fmt .Sprintf ("%s/%d /channel/list" , c .getChanelBaseEndpoint (), r .AccountID ),
215217 nil ,
216218 )
217219 if err != nil {
@@ -231,7 +233,7 @@ func (c *Client) Channel(ctx context.Context, r ChannelRequest) (*ChannelReply,
231233 req , err := http .NewRequestWithContext (
232234 ctx ,
233235 http .MethodGet ,
234- fmt .Sprintf ("%s/%s /channel/%s" , c .getChanelBaseEndpoint (), r .AccountID , r .ChannelID ),
236+ fmt .Sprintf ("%s/%d /channel/%s" , c .getChanelBaseEndpoint (), r .AccountID , r .ChannelID ),
235237 nil ,
236238 )
237239
@@ -257,7 +259,7 @@ func (c *Client) ChannelUpdate(ctx context.Context, r ChannelUpdateRequest) (*Ch
257259 req , err := http .NewRequestWithContext (
258260 ctx ,
259261 http .MethodPost ,
260- fmt .Sprintf ("%s/%s /channel/%s" , c .getChanelBaseEndpoint (), r .AccountID , r .ChannelID ),
262+ fmt .Sprintf ("%s/%d /channel/%s" , c .getChanelBaseEndpoint (), r .AccountID , r .ChannelID ),
261263 bytes .NewBuffer (payload ),
262264 )
263265
@@ -278,7 +280,7 @@ func (c *Client) ChannelDelete(ctx context.Context, r ChannelDeleteRequest) erro
278280 req , err := http .NewRequestWithContext (
279281 ctx ,
280282 http .MethodDelete ,
281- fmt .Sprintf ("%s/%s /channel/%s" , c .getChanelBaseEndpoint (), r .AccountID , r .ChannelID ),
283+ fmt .Sprintf ("%s/%d /channel/%s" , c .getChanelBaseEndpoint (), r .AccountID , r .ChannelID ),
282284 nil ,
283285 )
284286
@@ -299,7 +301,7 @@ func (c *Client) ChannelCreate(ctx context.Context, r ChannelCreateRequest) (*Ch
299301 req , err := http .NewRequestWithContext (
300302 ctx ,
301303 http .MethodPost ,
302- fmt .Sprintf ("%s/%s /channel" , c .getChanelBaseEndpoint (), r .AccountID ),
304+ fmt .Sprintf ("%s/%d /channel" , c .getChanelBaseEndpoint (), r .AccountID ),
303305 bytes .NewBuffer (payload ),
304306 )
305307
0 commit comments