Skip to content

Commit 416b3c3

Browse files
committed
♻️ Handle maxResults in Option
1 parent afe9cef commit 416b3c3

File tree

12 files changed

+34
-38
lines changed

12 files changed

+34
-38
lines changed

pkg/activity/activity.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ func (a *activity) Get(parts []string) ([]*youtube.Activity, error) {
5656
call = call.Mine(*a.Mine)
5757
}
5858

59-
if a.MaxResults <= 0 {
60-
a.MaxResults = 1
61-
}
6259
call.MaxResults(a.MaxResults)
6360

6461
if a.PublishedAfter != "" {
@@ -129,6 +126,9 @@ func WithHome(home *bool) Option {
129126

130127
func WithMaxResults(maxResults int64) Option {
131128
return func(a *activity) {
129+
if maxResults <= 0 {
130+
maxResults = 1
131+
}
132132
a.MaxResults = maxResults
133133
}
134134
}

pkg/channel/channel.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (c *channel) Get(parts []string) ([]*youtube.Channel, error) {
6262
}
6363

6464
if c.ForHandle != "" {
65-
call = call.ForUsername(c.ForHandle)
65+
call = call.ForHandle(c.ForHandle)
6666
}
6767

6868
if c.ForUsername != "" {
@@ -81,9 +81,6 @@ func (c *channel) Get(parts []string) ([]*youtube.Channel, error) {
8181
call = call.ManagedByMe(*c.ManagedByMe)
8282
}
8383

84-
if c.MaxResults <= 0 {
85-
c.MaxResults = 1
86-
}
8784
call = call.MaxResults(c.MaxResults)
8885

8986
if c.Mine != nil {
@@ -220,6 +217,9 @@ func WithChannelManagedByMe(managedByMe *bool) Option {
220217

221218
func WithMaxResults(maxResults int64) Option {
222219
return func(c *channel) {
220+
if maxResults <= 0 {
221+
maxResults = 1
222+
}
223223
c.MaxResults = maxResults
224224
}
225225
}

pkg/comment/comment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ func (c *comment) Get(parts []string) ([]*youtube.Comment, error) {
6565
call = call.Id(c.IDs...)
6666
}
6767

68-
if c.MaxResults <= 0 {
69-
c.MaxResults = 1
70-
}
7168
call = call.MaxResults(c.MaxResults)
7269

7370
if c.ParentId != "" {
@@ -283,6 +280,9 @@ func WithChannelId(channelId string) Option {
283280

284281
func WithMaxResults(maxResults int64) Option {
285282
return func(c *comment) {
283+
if maxResults <= 0 {
284+
maxResults = 1
285+
}
286286
c.MaxResults = maxResults
287287
}
288288
}

pkg/commentThread/commentThread.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ func (c *commentThread) Get(parts []string) ([]*youtube.CommentThread, error) {
6464
call = call.ChannelId(c.ChannelId)
6565
}
6666

67-
if c.MaxResults <= 0 {
68-
c.MaxResults = 1
69-
}
7067
call = call.MaxResults(c.MaxResults)
7168

7269
if c.ModerationStatus != "" {
@@ -192,6 +189,9 @@ func WithIDs(ids []string) Option {
192189

193190
func WithMaxResults(maxResults int64) Option {
194191
return func(c *commentThread) {
192+
if maxResults <= 0 {
193+
maxResults = 1
194+
}
195195
c.MaxResults = maxResults
196196
}
197197
}

pkg/member/member.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ func (m *member) Get(parts []string) ([]*youtube.Member, error) {
4747
if m.HasAccessToLevel != "" {
4848
call = call.HasAccessToLevel(m.HasAccessToLevel)
4949
}
50-
if m.MaxResults <= 0 {
51-
m.MaxResults = 1
52-
}
5350
call = call.MaxResults(m.MaxResults)
5451
if m.Mode != "" {
5552
call = call.Mode(m.Mode)

pkg/playlist/playlist.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ func (p *playlist) Get(parts []string) ([]*youtube.Playlist, error) {
6767
if p.Mine != nil {
6868
call = call.Mine(*p.Mine)
6969
}
70-
if p.MaxResults <= 0 {
71-
p.MaxResults = 1
72-
}
7370
call = call.MaxResults(p.MaxResults)
7471
if p.OnBehalfOfContentOwner != "" {
7572
call = call.OnBehalfOfContentOwner(p.OnBehalfOfContentOwner)
@@ -255,6 +252,9 @@ func WithHl(hl string) Option {
255252

256253
func WithMaxResults(maxResults int64) Option {
257254
return func(p *playlist) {
255+
if maxResults <= 0 {
256+
maxResults = 1
257+
}
258258
p.MaxResults = maxResults
259259
}
260260
}

pkg/playlistImage/playlistImage.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ func (pi *playlistImage) Get(parts []string) ([]*youtube.PlaylistImage, error) {
6666
if pi.OnBehalfOfContentOwnerChannel != "" {
6767
call = call.OnBehalfOfContentOwnerChannel(pi.OnBehalfOfContentOwnerChannel)
6868
}
69-
if pi.MaxResults <= 0 {
70-
pi.MaxResults = 1
71-
}
7269
call = call.MaxResults(pi.MaxResults)
7370

7471
res, err := call.Do()
@@ -270,6 +267,9 @@ func WithParent(parent string) Option {
270267

271268
func WithMaxResults(maxResults int64) Option {
272269
return func(pi *playlistImage) {
270+
if maxResults <= 0 {
271+
maxResults = 1
272+
}
273273
pi.MaxResults = maxResults
274274
}
275275
}

pkg/playlistItem/playlistItem.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ func (pi *playlistItem) Get(parts []string) ([]*youtube.PlaylistItem, error) {
7070
if pi.VideoId != "" {
7171
call = call.VideoId(pi.VideoId)
7272
}
73-
if pi.MaxResults <= 0 {
74-
pi.MaxResults = 1
75-
}
7673
call = call.MaxResults(pi.MaxResults)
7774
res, err := call.Do()
7875
if err != nil {
@@ -312,6 +309,9 @@ func WithPrivacy(privacy string) Option {
312309

313310
func WithMaxResults(maxResults int64) Option {
314311
return func(p *playlistItem) {
312+
if maxResults <= 0 {
313+
maxResults = 1
314+
}
315315
p.MaxResults = maxResults
316316
}
317317
}

pkg/search/search.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ func (s *search) Get(parts []string) ([]*youtube.SearchResult, error) {
9898
call.LocationRadius(s.LocationRadius)
9999
}
100100

101-
if s.MaxResults <= 0 {
102-
s.MaxResults = 1
103-
}
104101
call.MaxResults(s.MaxResults)
105102

106103
if s.OnBehalfOfContentOwner != "" {
@@ -285,6 +282,9 @@ func WithLocationRadius(locationRadius string) Option {
285282

286283
func WithMaxResults(maxResults int64) Option {
287284
return func(s *search) {
285+
if maxResults <= 0 {
286+
maxResults = 1
287+
}
288288
s.MaxResults = maxResults
289289
}
290290
}

pkg/subscription/subscription.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ func (s *subscription) Get(parts []string) ([]*youtube.Subscription, error) {
6464
if s.ForChannelId != "" {
6565
call = call.ForChannelId(s.ForChannelId)
6666
}
67-
if s.MaxResults <= 0 {
68-
s.MaxResults = 1
69-
}
7067
call = call.MaxResults(s.MaxResults)
7168

7269
if s.Mine != nil {
@@ -213,6 +210,9 @@ func WithForChannelId(forChannelId string) Option {
213210

214211
func WithMaxResults(maxResults int64) Option {
215212
return func(s *subscription) {
213+
if maxResults <= 0 {
214+
maxResults = 1
215+
}
216216
s.MaxResults = maxResults
217217
}
218218
}

0 commit comments

Comments
 (0)