Skip to content

Commit 445b1fa

Browse files
committed
✨ Allow read env when init youtube service
1 parent 44bb314 commit 445b1fa

File tree

20 files changed

+146
-102
lines changed

20 files changed

+146
-102
lines changed

pkg/activity/activity.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,13 @@ func WithRegionCode(regionCode string) Option {
144144
}
145145

146146
func WithService(svc *youtube.Service) Option {
147-
return func(a *activity) {
148-
if svc != nil {
149-
service = svc
150-
} else {
151-
service = auth.NewY2BService()
147+
return func(_ *activity) {
148+
if svc == nil {
149+
svc = auth.NewY2BService(
150+
auth.WithCredential(""),
151+
auth.WithCacheToken(""),
152+
)
152153
}
154+
service = svc
153155
}
154156
}

pkg/caption/caption.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,13 @@ func WithTlang(tlang string) Option {
376376
}
377377

378378
func WithService(svc *youtube.Service) Option {
379-
return func(c *caption) {
380-
if svc != nil {
381-
service = svc
382-
} else {
383-
service = auth.NewY2BService()
379+
return func(_ *caption) {
380+
if svc == nil {
381+
svc = auth.NewY2BService(
382+
auth.WithCredential(""),
383+
auth.WithCacheToken(""),
384+
)
384385
}
386+
service = svc
385387
}
386388
}

pkg/channel/channel.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,13 @@ func WithTitle(title string) Option {
246246
}
247247

248248
func WithService(svc *youtube.Service) Option {
249-
return func(c *channel) {
250-
if svc != nil {
251-
service = svc
252-
} else {
253-
service = auth.NewY2BService()
249+
return func(_ *channel) {
250+
if svc == nil {
251+
svc = auth.NewY2BService(
252+
auth.WithCredential(""),
253+
auth.WithCacheToken(""),
254+
)
254255
}
256+
service = svc
255257
}
256258
}

pkg/channelBanner/channelBanner.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ func WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel string) Opt
9191
}
9292

9393
func WithService(svc *youtube.Service) Option {
94-
return func(cb *channelBanner) {
95-
if svc != nil {
96-
service = svc
97-
} else {
98-
service = auth.NewY2BService()
94+
return func(_ *channelBanner) {
95+
if svc == nil {
96+
svc = auth.NewY2BService(
97+
auth.WithCredential(""),
98+
auth.WithCacheToken(""),
99+
)
99100
}
101+
service = svc
100102
}
101103
}

pkg/channelSection/channelSection.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,13 @@ func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option {
134134
}
135135

136136
func WithService(svc *youtube.Service) Option {
137-
return func(cs *channelSection) {
138-
if svc != nil {
139-
service = svc
140-
} else {
141-
service = auth.NewY2BService()
137+
return func(_ *channelSection) {
138+
if svc == nil {
139+
svc = auth.NewY2BService(
140+
auth.WithCredential(""),
141+
auth.WithCacheToken(""),
142+
)
142143
}
144+
service = svc
143145
}
144146
}

pkg/comment/comment.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ func (c *comment) SetModerationStatus(output string) {
212212
utils.PrintYAML(c)
213213
case "silent":
214214
default:
215-
fmt.Printf("Comment moderation status set to %s: %s\n", c.ModerationStatus, c.IDs)
215+
fmt.Printf(
216+
"Comment moderation status set to %s: %s\n", c.ModerationStatus, c.IDs,
217+
)
216218
}
217219
}
218220

@@ -304,11 +306,13 @@ func WithViewerRating(viewerRating string) Option {
304306
}
305307

306308
func WithService(svc *youtube.Service) Option {
307-
return func(c *comment) {
308-
if svc != nil {
309-
service = svc
310-
} else {
311-
service = auth.NewY2BService()
309+
return func(_ *comment) {
310+
if svc == nil {
311+
svc = auth.NewY2BService(
312+
auth.WithCredential(""),
313+
auth.WithCacheToken(""),
314+
)
312315
}
316+
service = svc
313317
}
314318
}

pkg/commentThread/commentThread.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ func (c *commentThread) List(parts []string, output string) {
106106
default:
107107
fmt.Println("ID\tTopLevelCommentID")
108108
for _, commentThread := range commentThreads {
109-
fmt.Printf("%s\t%s\n", commentThread.Id, commentThread.Snippet.TopLevelComment.Id)
109+
fmt.Printf(
110+
"%s\t%s\n", commentThread.Id, commentThread.Snippet.TopLevelComment.Id,
111+
)
110112
}
111113
}
112114
}
@@ -212,11 +214,13 @@ func WithVideoId(videoId string) Option {
212214
}
213215

214216
func WithService(svc *youtube.Service) Option {
215-
return func(c *commentThread) {
216-
if svc != nil {
217-
service = svc
218-
} else {
219-
service = auth.NewY2BService()
217+
return func(_ *commentThread) {
218+
if svc == nil {
219+
svc = auth.NewY2BService(
220+
auth.WithCredential(""),
221+
auth.WithCacheToken(""),
222+
)
220223
}
224+
service = svc
221225
}
222226
}

pkg/i18nLanguage/i18nLanguage.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ func WithHl(hl string) Option {
7575
}
7676

7777
func WithService(svc *youtube.Service) Option {
78-
return func(i *i18nLanguage) {
79-
if svc != nil {
80-
service = svc
81-
} else {
82-
service = auth.NewY2BService()
78+
return func(_ *i18nLanguage) {
79+
if svc == nil {
80+
svc = auth.NewY2BService(
81+
auth.WithCredential(""),
82+
auth.WithCacheToken(""),
83+
)
8384
}
85+
service = svc
8486
}
8587
}

pkg/i18nRegion/i18nRegion.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ func WithHl(hl string) Option {
7575
}
7676

7777
func WithService(svc *youtube.Service) Option {
78-
return func(i *i18nRegion) {
79-
if svc != nil {
80-
service = svc
81-
} else {
82-
service = auth.NewY2BService()
78+
return func(_ *i18nRegion) {
79+
if svc == nil {
80+
svc = auth.NewY2BService(
81+
auth.WithCredential(""),
82+
auth.WithCacheToken(""),
83+
)
8384
}
85+
service = svc
8486
}
8587
}

pkg/member/member.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,13 @@ func WithMode(mode string) Option {
107107
}
108108

109109
func WithService(svc *youtube.Service) Option {
110-
return func(m *member) {
111-
if svc != nil {
112-
service = svc
113-
} else {
114-
service = auth.NewY2BService()
110+
return func(_ *member) {
111+
if svc == nil {
112+
svc = auth.NewY2BService(
113+
auth.WithCredential(""),
114+
auth.WithCacheToken(""),
115+
)
115116
}
117+
service = svc
116118
}
117119
}

0 commit comments

Comments
 (0)