Skip to content

Commit

Permalink
✨ Allow read env when init youtube service
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenWaygate committed Nov 25, 2024
1 parent 44bb314 commit 445b1fa
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 102 deletions.
12 changes: 7 additions & 5 deletions pkg/activity/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ func WithRegionCode(regionCode string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(a *activity) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *activity) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/caption/caption.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,13 @@ func WithTlang(tlang string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(c *caption) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *caption) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,13 @@ func WithTitle(title string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(c *channel) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *channel) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/channelBanner/channelBanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ func WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel string) Opt
}

func WithService(svc *youtube.Service) Option {
return func(cb *channelBanner) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *channelBanner) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/channelSection/channelSection.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(cs *channelSection) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *channelSection) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
16 changes: 10 additions & 6 deletions pkg/comment/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ func (c *comment) SetModerationStatus(output string) {
utils.PrintYAML(c)
case "silent":
default:
fmt.Printf("Comment moderation status set to %s: %s\n", c.ModerationStatus, c.IDs)
fmt.Printf(
"Comment moderation status set to %s: %s\n", c.ModerationStatus, c.IDs,
)
}
}

Expand Down Expand Up @@ -304,11 +306,13 @@ func WithViewerRating(viewerRating string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(c *comment) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *comment) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
16 changes: 10 additions & 6 deletions pkg/commentThread/commentThread.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ func (c *commentThread) List(parts []string, output string) {
default:
fmt.Println("ID\tTopLevelCommentID")
for _, commentThread := range commentThreads {
fmt.Printf("%s\t%s\n", commentThread.Id, commentThread.Snippet.TopLevelComment.Id)
fmt.Printf(
"%s\t%s\n", commentThread.Id, commentThread.Snippet.TopLevelComment.Id,
)
}
}
}
Expand Down Expand Up @@ -212,11 +214,13 @@ func WithVideoId(videoId string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(c *commentThread) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *commentThread) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/i18nLanguage/i18nLanguage.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ func WithHl(hl string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(i *i18nLanguage) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *i18nLanguage) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/i18nRegion/i18nRegion.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ func WithHl(hl string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(i *i18nRegion) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *i18nRegion) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/member/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ func WithMode(mode string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(m *member) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *member) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/membershipsLevel/membershipsLevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ func (m *membershipsLevel) List(parts []string, output string) {
}

func WithService(svc *youtube.Service) Option {
return func(m *membershipsLevel) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *membershipsLevel) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/playlist/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,13 @@ func WithOnBehalfOfContentOwnerChannel(channel string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(p *playlist) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *playlist) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/playlistItem/playlistItem.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,13 @@ func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(p *playlistItem) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *playlistItem) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,13 @@ func WithVideoType(videoType string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(s *search) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *search) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/subscription/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,13 @@ func WithTitle(title string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(s *subscription) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *subscription) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/thumbnail/thumbnail.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ func WithFile(file string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(t *thumbnail) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *thumbnail) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/video/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,13 @@ func WithSecondaryReasonId(secondaryReasonId string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(v *video) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *video) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/videoAbuseReportReason/videoAbuseReportReason.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ func WithHL(hl string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(vc *videoAbuseReportReason) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *videoAbuseReportReason) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
12 changes: 7 additions & 5 deletions pkg/videoCategory/videoCategory.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ func WithRegionCode(regionCode string) Option {
}

func WithService(svc *youtube.Service) Option {
return func(vc *videoCategory) {
if svc != nil {
service = svc
} else {
service = auth.NewY2BService()
return func(_ *videoCategory) {
if svc == nil {
svc = auth.NewY2BService(
auth.WithCredential(""),
auth.WithCacheToken(""),
)
}
service = svc
}
}
Loading

0 comments on commit 445b1fa

Please sign in to comment.