diff --git a/.goreleaser.yaml b/.goreleaser.yaml
index 9e4a10a..7dcb118 100644
--- a/.goreleaser.yaml
+++ b/.goreleaser.yaml
@@ -58,7 +58,7 @@ builds:
mod_timestamp: "{{ .CommitTimestamp }}"
archives:
- - formats: ["binary"]
+ - formats: [ "binary" ]
ids:
- yutu
name_template: "{{ .Binary }}"
diff --git a/assets/yutu-ico.svg b/assets/yutu-ico.svg
index b0ac7e2..dfa239c 100644
--- a/assets/yutu-ico.svg
+++ b/assets/yutu-ico.svg
@@ -1,3 +1,57 @@
-
\ No newline at end of file
+
diff --git a/assets/yutu.svg b/assets/yutu.svg
index ebb67db..6182613 100644
--- a/assets/yutu.svg
+++ b/assets/yutu.svg
@@ -1,4 +1,91 @@
-
\ No newline at end of file
+
diff --git a/npm/yutu/bin/yutu b/npm/yutu/bin/yutu
index 31415ab..900ce9f 100644
--- a/npm/yutu/bin/yutu
+++ b/npm/yutu/bin/yutu
@@ -2,7 +2,7 @@
"use strict";
-const { execFileSync } = require("child_process");
+const {execFileSync} = require("child_process");
const os = require("os");
const PLATFORMS = {
@@ -21,7 +21,7 @@ function getBinaryPath() {
if (!pkg) {
throw new Error(
`Unsupported platform: ${platformKey}. ` +
- `yutu supports: ${Object.keys(PLATFORMS).join(", ")}`
+ `yutu supports: ${Object.keys(PLATFORMS).join(", ")}`
);
}
@@ -40,16 +40,16 @@ function getBinaryPath() {
}
throw new Error(
`You installed yutu for ${key} but this platform is ${platformKey}.\n` +
- `This can happen when copying node_modules between platforms.\n` +
- `Run "npm install" on this platform to fix.`
+ `This can happen when copying node_modules between platforms.\n` +
+ `Run "npm install" on this platform to fix.`
);
}
throw new Error(
`The package "${pkg}" could not be found, and is needed by yutu.\n\n` +
- `If you installed with npm, make sure you don't use the "--no-optional"\n` +
- `or "--omit=optional" flags. The "optionalDependencies" feature is used\n` +
- `by yutu to install the correct binary for your platform.`
+ `If you installed with npm, make sure you don't use the "--no-optional"\n` +
+ `or "--omit=optional" flags. The "optionalDependencies" feature is used\n` +
+ `by yutu to install the correct binary for your platform.`
);
}
}
diff --git a/pkg/activity/activity.go b/pkg/activity/activity.go
index d649af7..59892f7 100644
--- a/pkg/activity/activity.go
+++ b/pkg/activity/activity.go
@@ -69,9 +69,12 @@ func (a *Activity) Get() ([]*youtube.Activity, error) {
call = call.RegionCode(a.RegionCode)
}
- return common.Paginate(a.Fields, call, func(r *youtube.ActivityListResponse) ([]*youtube.Activity, string) {
- return r.Items, r.NextPageToken
- }, errGetActivity)
+ return common.Paginate(
+ a.Fields, call,
+ func(r *youtube.ActivityListResponse) ([]*youtube.Activity, string) {
+ return r.Items, r.NextPageToken
+ }, errGetActivity,
+ )
}
func (a *Activity) List(writer io.Writer) error {
@@ -80,9 +83,12 @@ func (a *Activity) List(writer io.Writer) error {
return err
}
- common.PrintList(a.Output, activities, writer, table.Row{"ID", "Title", "Type", "Time"}, func(a *youtube.Activity) table.Row {
- return table.Row{a.Id, a.Snippet.Title, a.Snippet.Type, a.Snippet.PublishedAt}
- })
+ common.PrintList(
+ a.Output, activities, writer, table.Row{"ID", "Title", "Type", "Time"},
+ func(a *youtube.Activity) table.Row {
+ return table.Row{a.Id, a.Snippet.Title, a.Snippet.Type, a.Snippet.PublishedAt}
+ },
+ )
return err
}
diff --git a/pkg/activity/activity_test.go b/pkg/activity/activity_test.go
index 225936b..c10a092 100644
--- a/pkg/activity/activity_test.go
+++ b/pkg/activity/activity_test.go
@@ -287,23 +287,25 @@ func TestActivity_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "1", "snippet": {"title": "A1"}},
{"id": "2", "snippet": {"title": "A2"}}
],
"nextPageToken": ""
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
a := NewActivity(opts...)
@@ -378,12 +380,14 @@ func TestActivity_List(t *testing.T) {
"nextPageToken": ""
}`
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(mockResponse))
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(mockResponse))
+ },
+ ),
+ )
tests := []struct {
name string
diff --git a/pkg/auth/auth_test.go b/pkg/auth/auth_test.go
index 88d6f1e..21a7415 100644
--- a/pkg/auth/auth_test.go
+++ b/pkg/auth/auth_test.go
@@ -155,7 +155,9 @@ func TestGetCodeFromPrompt_Success(t *testing.T) {
s := NewY2BService(WithIO(in, &out)).(*svc)
- code, err := s.getCodeFromPrompt("http://example.com/auth", "http://localhost:8216")
+ code, err := s.getCodeFromPrompt(
+ "http://example.com/auth", "http://localhost:8216",
+ )
if err != nil {
t.Fatalf("getCodeFromPrompt returned error: %v", err)
}
@@ -164,7 +166,9 @@ func TestGetCodeFromPrompt_Success(t *testing.T) {
}
outStr := out.String()
- if !strings.Contains(outStr, openBrowserHint[:20]) { // basic sanity check that hint was written
+ if !strings.Contains(
+ outStr, openBrowserHint[:20],
+ ) { // basic sanity check that hint was written
t.Fatalf("expected openBrowserHint to be written to out, got %q", outStr)
}
if !strings.Contains(outStr, "After completing the authorization flow") {
@@ -181,7 +185,9 @@ func TestGetCodeFromPrompt_URLDecode(t *testing.T) {
s := NewY2BService(WithIO(in, &out)).(*svc)
- code, err := s.getCodeFromPrompt("http://example.com/auth", "http://localhost:8216")
+ code, err := s.getCodeFromPrompt(
+ "http://example.com/auth", "http://localhost:8216",
+ )
if err != nil {
t.Fatalf("getCodeFromPrompt returned error: %v", err)
}
diff --git a/pkg/caption/caption.go b/pkg/caption/caption.go
index 9ab442d..69b3ed3 100644
--- a/pkg/caption/caption.go
+++ b/pkg/caption/caption.go
@@ -93,9 +93,12 @@ func (c *Caption) List(writer io.Writer) error {
return err
}
- common.PrintList(c.Output, captions, writer, table.Row{"ID", "Video ID", "Name", "Language"}, func(cap *youtube.Caption) table.Row {
- return table.Row{cap.Id, cap.Snippet.VideoId, cap.Snippet.Name, cap.Snippet.Language}
- })
+ common.PrintList(
+ c.Output, captions, writer, table.Row{"ID", "Video ID", "Name", "Language"},
+ func(cap *youtube.Caption) table.Row {
+ return table.Row{cap.Id, cap.Snippet.VideoId, cap.Snippet.Name, cap.Snippet.Language}
+ },
+ )
return nil
}
diff --git a/pkg/caption/caption_test.go b/pkg/caption/caption_test.go
index 47343a9..0376b12 100644
--- a/pkg/caption/caption_test.go
+++ b/pkg/caption/caption_test.go
@@ -271,22 +271,24 @@ func TestCaption_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "1", "snippet": {"videoId": "video-id"}},
{"id": "2", "snippet": {"videoId": "video-id"}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewCaption(opts...)
@@ -306,11 +308,12 @@ func TestCaption_Get(t *testing.T) {
}
func TestCaption_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "caption-1",
@@ -322,9 +325,10 @@ func TestCaption_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
@@ -451,15 +455,17 @@ func TestCaption_Insert(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(`{"id": "new-caption-id", "snippet": {"videoId": "video-id"}}`))
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"id": "new-caption-id", "snippet": {"videoId": "video-id"}}`))
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewCaption(opts...)
@@ -546,25 +552,27 @@ func TestCaption_Update(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- if r.Method == "GET" {
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ if r.Method == "GET" {
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "caption-id", "snippet": {"videoId": "video-id", "language": "en"}}
]
}`),
- )
- } else {
- _, _ = w.Write([]byte(`{"id": "caption-id", "snippet": {"videoId": "video-id", "language": "es"}}`))
- }
- },
- ))
+ )
+ } else {
+ _, _ = w.Write([]byte(`{"id": "caption-id", "snippet": {"videoId": "video-id", "language": "es"}}`))
+ }
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewCaption(opts...)
@@ -633,14 +641,16 @@ func TestCaption_Delete(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewCaption(opts...)
@@ -740,14 +750,16 @@ func TestCaption_Download(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- _, _ = w.Write([]byte("1\n00:00:01,000 --> 00:00:04,000\nDownloaded Caption"))
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ _, _ = w.Write([]byte("1\n00:00:01,000 --> 00:00:04,000\nDownloaded Caption"))
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewCaption(opts...)
diff --git a/pkg/channel/channel.go b/pkg/channel/channel.go
index 31c3ee3..efe36d1 100644
--- a/pkg/channel/channel.go
+++ b/pkg/channel/channel.go
@@ -82,9 +82,12 @@ func (c *Channel) Get() ([]*youtube.Channel, error) {
call = call.OnBehalfOfContentOwner(c.OnBehalfOfContentOwner)
}
- return common.Paginate(c.Fields, call, func(r *youtube.ChannelListResponse) ([]*youtube.Channel, string) {
- return r.Items, r.NextPageToken
- }, errGetChannel)
+ return common.Paginate(
+ c.Fields, call,
+ func(r *youtube.ChannelListResponse) ([]*youtube.Channel, string) {
+ return r.Items, r.NextPageToken
+ }, errGetChannel,
+ )
}
func (c *Channel) List(writer io.Writer) error {
@@ -93,15 +96,18 @@ func (c *Channel) List(writer io.Writer) error {
return err
}
- common.PrintList(c.Output, channels, writer, table.Row{"ID", "Title", "Country"}, func(ch *youtube.Channel) table.Row {
- title := ""
- country := ""
- if ch.Snippet != nil {
- title = ch.Snippet.Title
- country = ch.Snippet.Country
- }
- return table.Row{ch.Id, title, country}
- })
+ common.PrintList(
+ c.Output, channels, writer, table.Row{"ID", "Title", "Country"},
+ func(ch *youtube.Channel) table.Row {
+ title := ""
+ country := ""
+ if ch.Snippet != nil {
+ title = ch.Snippet.Title
+ country = ch.Snippet.Country
+ }
+ return table.Row{ch.Id, title, country}
+ },
+ )
return err
}
diff --git a/pkg/channel/channel_test.go b/pkg/channel/channel_test.go
index 14e5752..b4dcd68 100644
--- a/pkg/channel/channel_test.go
+++ b/pkg/channel/channel_test.go
@@ -376,21 +376,23 @@ func TestChannel_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "channel-1", "snippet": {"title": "Channel 1"}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewChannel(opts...)
@@ -452,11 +454,12 @@ func TestChannel_Get_Pagination(t *testing.T) {
}
func TestChannel_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "channel-1",
@@ -467,9 +470,10 @@ func TestChannel_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
@@ -578,25 +582,27 @@ func TestChannel_Update(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- if r.Method == "GET" {
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ if r.Method == "GET" {
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "channel-id", "snippet": {"title": "Old Title"}}
]
}`),
- )
- } else {
- _, _ = w.Write([]byte(`{"id": "channel-id", "snippet": {"title": "New Title"}}`))
- }
- },
- ))
+ )
+ } else {
+ _, _ = w.Write([]byte(`{"id": "channel-id", "snippet": {"title": "New Title"}}`))
+ }
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewChannel(opts...)
diff --git a/pkg/channelBanner/channelBanner.go b/pkg/channelBanner/channelBanner.go
index 895cdba..916ad6f 100644
--- a/pkg/channelBanner/channelBanner.go
+++ b/pkg/channelBanner/channelBanner.go
@@ -64,7 +64,9 @@ func (cb *ChannelBanner) Insert(writer io.Writer) error {
return errors.Join(errInsertChannelBanner, err)
}
- common.PrintResult(cb.Output, res, writer, "ChannelBanner inserted: %s\n", res.Url)
+ common.PrintResult(
+ cb.Output, res, writer, "ChannelBanner inserted: %s\n", res.Url,
+ )
return nil
}
diff --git a/pkg/channelBanner/channelBanner_test.go b/pkg/channelBanner/channelBanner_test.go
index fce0b6d..202a2a5 100644
--- a/pkg/channelBanner/channelBanner_test.go
+++ b/pkg/channelBanner/channelBanner_test.go
@@ -299,15 +299,17 @@ func TestChannelBanner_Insert(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(`{"url": "https://example.com/banner.jpg"}`))
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"url": "https://example.com/banner.jpg"}`))
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
cb := NewChannelBanner(opts...)
diff --git a/pkg/channelSection/channelSection.go b/pkg/channelSection/channelSection.go
index 0bd38ed..6656045 100644
--- a/pkg/channelSection/channelSection.go
+++ b/pkg/channelSection/channelSection.go
@@ -81,9 +81,12 @@ func (cs *ChannelSection) List(writer io.Writer) error {
return err
}
- common.PrintList(cs.Output, channelSections, writer, table.Row{"ID", "Channel ID", "Title"}, func(s *youtube.ChannelSection) table.Row {
- return table.Row{s.Id, s.Snippet.ChannelId, s.Snippet.Title}
- })
+ common.PrintList(
+ cs.Output, channelSections, writer, table.Row{"ID", "Channel ID", "Title"},
+ func(s *youtube.ChannelSection) table.Row {
+ return table.Row{s.Id, s.Snippet.ChannelId, s.Snippet.Title}
+ },
+ )
return nil
}
diff --git a/pkg/channelSection/channelSection_test.go b/pkg/channelSection/channelSection_test.go
index 37a7c53..0c4f7bf 100644
--- a/pkg/channelSection/channelSection_test.go
+++ b/pkg/channelSection/channelSection_test.go
@@ -221,21 +221,23 @@ func TestChannelSection_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "section-1", "snippet": {"title": "Section 1"}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
cs := NewChannelSection(opts...)
@@ -258,11 +260,12 @@ func TestChannelSection_Get(t *testing.T) {
}
func TestChannelSection_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "section-1",
@@ -273,9 +276,10 @@ func TestChannelSection_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
@@ -373,14 +377,16 @@ func TestChannelSection_Delete(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
cs := NewChannelSection(opts...)
diff --git a/pkg/comment/comment.go b/pkg/comment/comment.go
index 1fb2849..44a0758 100644
--- a/pkg/comment/comment.go
+++ b/pkg/comment/comment.go
@@ -24,15 +24,15 @@ var (
type Comment struct {
*common.Fields
- AuthorChannelId string `yaml:"author_channel_id" json:"author_channel_id,omitempty"`
- CanRate *bool `yaml:"can_rate" json:"can_rate,omitempty"`
- ParentId string `yaml:"parent_id" json:"parent_id,omitempty"`
- TextFormat string `yaml:"text_format" json:"text_format,omitempty"`
- TextOriginal string `yaml:"text_original" json:"text_original,omitempty"`
- ModerationStatus string `yaml:"moderation_status" json:"moderation_status,omitempty"`
- BanAuthor *bool `yaml:"ban_author" json:"ban_author,omitempty"`
- VideoId string `yaml:"video_id" json:"video_id,omitempty"`
- ViewerRating string `yaml:"viewer_rating" json:"viewer_rating,omitempty"`
+ AuthorChannelId string `yaml:"author_channel_id" json:"author_channel_id,omitempty"`
+ CanRate *bool `yaml:"can_rate" json:"can_rate,omitempty"`
+ ParentId string `yaml:"parent_id" json:"parent_id,omitempty"`
+ TextFormat string `yaml:"text_format" json:"text_format,omitempty"`
+ TextOriginal string `yaml:"text_original" json:"text_original,omitempty"`
+ ModerationStatus string `yaml:"moderation_status" json:"moderation_status,omitempty"`
+ BanAuthor *bool `yaml:"ban_author" json:"ban_author,omitempty"`
+ VideoId string `yaml:"video_id" json:"video_id,omitempty"`
+ ViewerRating string `yaml:"viewer_rating" json:"viewer_rating,omitempty"`
}
type IComment[T any] interface {
@@ -70,9 +70,12 @@ func (c *Comment) Get() ([]*youtube.Comment, error) {
call = call.TextFormat(c.TextFormat)
}
- return common.Paginate(c.Fields, call, func(r *youtube.CommentListResponse) ([]*youtube.Comment, string) {
- return r.Items, r.NextPageToken
- }, errGetComment)
+ return common.Paginate(
+ c.Fields, call,
+ func(r *youtube.CommentListResponse) ([]*youtube.Comment, string) {
+ return r.Items, r.NextPageToken
+ }, errGetComment,
+ )
}
func (c *Comment) List(writer io.Writer) error {
@@ -81,17 +84,21 @@ func (c *Comment) List(writer io.Writer) error {
return err
}
- common.PrintList(c.Output, comments, writer, table.Row{"ID", "Author", "Video ID", "Text Display"}, func(cm *youtube.Comment) table.Row {
- author := ""
- videoId := ""
- textDisplay := ""
- if cm.Snippet != nil {
- author = cm.Snippet.AuthorDisplayName
- videoId = cm.Snippet.VideoId
- textDisplay = cm.Snippet.TextDisplay
- }
- return table.Row{cm.Id, author, videoId, textDisplay}
- })
+ common.PrintList(
+ c.Output, comments, writer,
+ table.Row{"ID", "Author", "Video ID", "Text Display"},
+ func(cm *youtube.Comment) table.Row {
+ author := ""
+ videoId := ""
+ textDisplay := ""
+ if cm.Snippet != nil {
+ author = cm.Snippet.AuthorDisplayName
+ videoId = cm.Snippet.VideoId
+ textDisplay = cm.Snippet.TextDisplay
+ }
+ return table.Row{cm.Id, author, videoId, textDisplay}
+ },
+ )
return err
}
@@ -191,7 +198,10 @@ func (c *Comment) SetModerationStatus(writer io.Writer) error {
return errors.Join(errSetModerationStatus, err)
}
- common.PrintResult(c.Output, c, writer, "Comment moderation status set to %s: %s\n", c.ModerationStatus, c.Ids)
+ common.PrintResult(
+ c.Output, c, writer, "Comment moderation status set to %s: %s\n",
+ c.ModerationStatus, c.Ids,
+ )
return nil
}
diff --git a/pkg/comment/comment_test.go b/pkg/comment/comment_test.go
index 64ac613..da1c880 100644
--- a/pkg/comment/comment_test.go
+++ b/pkg/comment/comment_test.go
@@ -55,12 +55,12 @@ func TestNewComment(t *testing.T) {
},
want: &Comment{
Fields: &common.Fields{
- Service: svc,
- Parts: []string{"id", "snippet"},
- Output: "json",
- Ids: []string{"comment1", "comment2"},
+ Service: svc,
+ Parts: []string{"id", "snippet"},
+ Output: "json",
+ Ids: []string{"comment1", "comment2"},
MaxResults: 50,
- ChannelId: "channel123",
+ ChannelId: "channel123",
},
AuthorChannelId: "author123",
CanRate: &canRateTrue,
@@ -242,21 +242,23 @@ func TestComment_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "comment-1", "snippet": {"textOriginal": "Comment 1"}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewComment(opts...)
@@ -318,11 +320,12 @@ func TestComment_Get_Pagination(t *testing.T) {
}
func TestComment_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "comment-1",
@@ -334,9 +337,10 @@ func TestComment_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
@@ -440,15 +444,17 @@ func TestComment_Insert(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(`{"id": "new-comment-id"}`))
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"id": "new-comment-id"}`))
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewComment(opts...)
@@ -509,21 +515,23 @@ func TestComment_Update(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- if r.Method == "GET" {
- _, _ = w.Write(
- []byte(`{"items": [{"id": "comment-id", "snippet": {"textOriginal": "Old Text"}}]}`),
- )
- } else {
- _, _ = w.Write([]byte(`{"id": "comment-id", "snippet": {"textOriginal": "Updated Text"}}`))
- }
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ if r.Method == "GET" {
+ _, _ = w.Write(
+ []byte(`{"items": [{"id": "comment-id", "snippet": {"textOriginal": "Old Text"}}]}`),
+ )
+ } else {
+ _, _ = w.Write([]byte(`{"id": "comment-id", "snippet": {"textOriginal": "Updated Text"}}`))
+ }
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewComment(opts...)
@@ -560,14 +568,16 @@ func TestComment_Delete(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewComment(opts...)
@@ -607,14 +617,16 @@ func TestComment_MarkAsSpam(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewComment(opts...)
@@ -680,14 +692,16 @@ func TestComment_SetModerationStatus(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewComment(opts...)
diff --git a/pkg/commentThread/commentThread.go b/pkg/commentThread/commentThread.go
index 7386e8a..39c955f 100644
--- a/pkg/commentThread/commentThread.go
+++ b/pkg/commentThread/commentThread.go
@@ -76,9 +76,12 @@ func (c *CommentThread) Get() ([]*youtube.CommentThread, error) {
call = call.VideoId(c.VideoId)
}
- return common.Paginate(c.Fields, call, func(r *youtube.CommentThreadListResponse) ([]*youtube.CommentThread, string) {
- return r.Items, r.NextPageToken
- }, errGetCommentThread)
+ return common.Paginate(
+ c.Fields, call,
+ func(r *youtube.CommentThreadListResponse) ([]*youtube.CommentThread, string) {
+ return r.Items, r.NextPageToken
+ }, errGetCommentThread,
+ )
}
func (c *CommentThread) List(writer io.Writer) error {
@@ -87,10 +90,14 @@ func (c *CommentThread) List(writer io.Writer) error {
return err
}
- common.PrintList(c.Output, commentThreads, writer, table.Row{"ID", "Author", "Video ID", "Text Display"}, func(cot *youtube.CommentThread) table.Row {
- snippet := cot.Snippet.TopLevelComment.Snippet
- return table.Row{cot.Id, snippet.AuthorDisplayName, snippet.VideoId, snippet.TextDisplay}
- })
+ common.PrintList(
+ c.Output, commentThreads, writer,
+ table.Row{"ID", "Author", "Video ID", "Text Display"},
+ func(cot *youtube.CommentThread) table.Row {
+ snippet := cot.Snippet.TopLevelComment.Snippet
+ return table.Row{cot.Id, snippet.AuthorDisplayName, snippet.VideoId, snippet.TextDisplay}
+ },
+ )
return err
}
@@ -119,7 +126,9 @@ func (c *CommentThread) Insert(writer io.Writer) error {
return errors.Join(errInsertCommentThread, err)
}
- common.PrintResult(c.Output, res, writer, "CommentThread inserted: %s\n", res.Id)
+ common.PrintResult(
+ c.Output, res, writer, "CommentThread inserted: %s\n", res.Id,
+ )
return nil
}
diff --git a/pkg/commentThread/commentThread_test.go b/pkg/commentThread/commentThread_test.go
index d32594b..32f029b 100644
--- a/pkg/commentThread/commentThread_test.go
+++ b/pkg/commentThread/commentThread_test.go
@@ -272,21 +272,23 @@ func TestCommentThread_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "thread-1", "snippet": {"topLevelComment": {"snippet": {"textDisplay": "Comment 1"}}}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewCommentThread(opts...)
@@ -348,11 +350,12 @@ func TestCommentThread_Get_Pagination(t *testing.T) {
}
func TestCommentThread_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "thread-1",
@@ -368,9 +371,10 @@ func TestCommentThread_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
@@ -472,15 +476,17 @@ func TestCommentThread_Insert(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(`{"id": "new-thread-id"}`))
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"id": "new-thread-id"}`))
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
c := NewCommentThread(opts...)
diff --git a/pkg/i18nLanguage/i18nLanguage.go b/pkg/i18nLanguage/i18nLanguage.go
index aa0a5ed..a47825d 100644
--- a/pkg/i18nLanguage/i18nLanguage.go
+++ b/pkg/i18nLanguage/i18nLanguage.go
@@ -60,14 +60,17 @@ func (i *I18nLanguage) List(writer io.Writer) error {
return err
}
- common.PrintList(i.Output, languages, writer, table.Row{"ID", "Hl", "Name"}, func(l *youtube.I18nLanguage) table.Row {
- return table.Row{l.Id, l.Snippet.Hl, l.Snippet.Name}
- })
+ common.PrintList(
+ i.Output, languages, writer, table.Row{"ID", "Hl", "Name"},
+ func(l *youtube.I18nLanguage) table.Row {
+ return table.Row{l.Id, l.Snippet.Hl, l.Snippet.Name}
+ },
+ )
return nil
}
var (
- WithHl = common.WithHl[*I18nLanguage]
+ WithHl = common.WithHl[*I18nLanguage]
WithParts = common.WithParts[*I18nLanguage]
WithOutput = common.WithOutput[*I18nLanguage]
WithService = common.WithService[*I18nLanguage]
diff --git a/pkg/i18nLanguage/i18nLanguage_test.go b/pkg/i18nLanguage/i18nLanguage_test.go
index a3c7fec..8965577 100644
--- a/pkg/i18nLanguage/i18nLanguage_test.go
+++ b/pkg/i18nLanguage/i18nLanguage_test.go
@@ -103,17 +103,19 @@ func TestI18nLanguage_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{"items": [{"id": "en", "snippet": {"hl": "en", "name": "English"}}]}`),
- )
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{"items": [{"id": "en", "snippet": {"hl": "en", "name": "English"}}]}`),
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
i := NewI18nLanguage(opts...)
@@ -133,11 +135,12 @@ func TestI18nLanguage_Get(t *testing.T) {
}
func TestI18nLanguage_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "en",
@@ -148,9 +151,10 @@ func TestI18nLanguage_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
diff --git a/pkg/i18nRegion/i18nRegion.go b/pkg/i18nRegion/i18nRegion.go
index ecd48fb..2ed7edc 100644
--- a/pkg/i18nRegion/i18nRegion.go
+++ b/pkg/i18nRegion/i18nRegion.go
@@ -58,14 +58,17 @@ func (i *I18nRegion) List(writer io.Writer) error {
return err
}
- common.PrintList(i.Output, regions, writer, table.Row{"ID", "Gl", "Name"}, func(r *youtube.I18nRegion) table.Row {
- return table.Row{r.Id, r.Snippet.Gl, r.Snippet.Name}
- })
+ common.PrintList(
+ i.Output, regions, writer, table.Row{"ID", "Gl", "Name"},
+ func(r *youtube.I18nRegion) table.Row {
+ return table.Row{r.Id, r.Snippet.Gl, r.Snippet.Name}
+ },
+ )
return nil
}
var (
- WithHl = common.WithHl[*I18nRegion]
+ WithHl = common.WithHl[*I18nRegion]
WithParts = common.WithParts[*I18nRegion]
WithOutput = common.WithOutput[*I18nRegion]
WithService = common.WithService[*I18nRegion]
diff --git a/pkg/i18nRegion/i18nRegion_test.go b/pkg/i18nRegion/i18nRegion_test.go
index be48484..7298c7c 100644
--- a/pkg/i18nRegion/i18nRegion_test.go
+++ b/pkg/i18nRegion/i18nRegion_test.go
@@ -103,17 +103,19 @@ func TestI18nRegion_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{"items": [{"id": "US", "snippet": {"gl": "US", "name": "United States"}}]}`),
- )
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{"items": [{"id": "US", "snippet": {"gl": "US", "name": "United States"}}]}`),
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
i := NewI18nRegion(opts...)
@@ -133,11 +135,12 @@ func TestI18nRegion_Get(t *testing.T) {
}
func TestI18nRegion_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "US",
@@ -148,9 +151,10 @@ func TestI18nRegion_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
diff --git a/pkg/member/member.go b/pkg/member/member.go
index 2f848b3..a106b8e 100644
--- a/pkg/member/member.go
+++ b/pkg/member/member.go
@@ -53,9 +53,12 @@ func (m *Member) Get() ([]*youtube.Member, error) {
call = call.Mode(m.Mode)
}
- return common.Paginate(m.Fields, call, func(r *youtube.MemberListResponse) ([]*youtube.Member, string) {
- return r.Items, r.NextPageToken
- }, errGetMember)
+ return common.Paginate(
+ m.Fields, call,
+ func(r *youtube.MemberListResponse) ([]*youtube.Member, string) {
+ return r.Items, r.NextPageToken
+ }, errGetMember,
+ )
}
func (m *Member) List(writer io.Writer) error {
@@ -64,9 +67,12 @@ func (m *Member) List(writer io.Writer) error {
return err
}
- common.PrintList(m.Output, members, writer, table.Row{"Channel ID", "Display Name"}, func(m *youtube.Member) table.Row {
- return table.Row{m.Snippet.MemberDetails.ChannelId, m.Snippet.MemberDetails.DisplayName}
- })
+ common.PrintList(
+ m.Output, members, writer, table.Row{"Channel ID", "Display Name"},
+ func(m *youtube.Member) table.Row {
+ return table.Row{m.Snippet.MemberDetails.ChannelId, m.Snippet.MemberDetails.DisplayName}
+ },
+ )
return err
}
diff --git a/pkg/member/member_test.go b/pkg/member/member_test.go
index d1a59e9..2117cfa 100644
--- a/pkg/member/member_test.go
+++ b/pkg/member/member_test.go
@@ -192,14 +192,15 @@ func TestMember_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"snippet": {
@@ -211,9 +212,10 @@ func TestMember_Get(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
m := NewMember(opts...)
@@ -273,11 +275,12 @@ func TestMember_Get_Pagination(t *testing.T) {
}
func TestMember_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"snippet": {
@@ -289,9 +292,10 @@ func TestMember_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
diff --git a/pkg/membershipsLevel/membershipsLevel.go b/pkg/membershipsLevel/membershipsLevel.go
index 7f3ae6b..ce42376 100644
--- a/pkg/membershipsLevel/membershipsLevel.go
+++ b/pkg/membershipsLevel/membershipsLevel.go
@@ -58,9 +58,12 @@ func (m *MembershipsLevel) List(writer io.Writer) error {
return err
}
- common.PrintList(m.Output, levels, writer, table.Row{"ID", "Display Name"}, func(ml *youtube.MembershipsLevel) table.Row {
- return table.Row{ml.Id, ml.Snippet.LevelDetails.DisplayName}
- })
+ common.PrintList(
+ m.Output, levels, writer, table.Row{"ID", "Display Name"},
+ func(ml *youtube.MembershipsLevel) table.Row {
+ return table.Row{ml.Id, ml.Snippet.LevelDetails.DisplayName}
+ },
+ )
return nil
}
diff --git a/pkg/membershipsLevel/membershipsLevel_test.go b/pkg/membershipsLevel/membershipsLevel_test.go
index 474ae21..ebf38bd 100644
--- a/pkg/membershipsLevel/membershipsLevel_test.go
+++ b/pkg/membershipsLevel/membershipsLevel_test.go
@@ -67,11 +67,12 @@ func TestNewMembershipsLevel(t *testing.T) {
}
func TestMembershipsLevel_Get(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "level-1",
@@ -83,9 +84,10 @@ func TestMembershipsLevel_Get(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
m := NewMembershipsLevel(WithService(svc))
got, err := m.Get()
@@ -98,11 +100,12 @@ func TestMembershipsLevel_Get(t *testing.T) {
}
func TestMembershipsLevel_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "level-1",
@@ -114,9 +117,10 @@ func TestMembershipsLevel_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
diff --git a/pkg/playlist/playlist.go b/pkg/playlist/playlist.go
index c875f29..e094cf9 100644
--- a/pkg/playlist/playlist.go
+++ b/pkg/playlist/playlist.go
@@ -75,9 +75,12 @@ func (p *Playlist) Get() ([]*youtube.Playlist, error) {
call = call.OnBehalfOfContentOwnerChannel(p.OnBehalfOfContentOwnerChannel)
}
- return common.Paginate(p.Fields, call, func(r *youtube.PlaylistListResponse) ([]*youtube.Playlist, string) {
- return r.Items, r.NextPageToken
- }, errGetPlaylist)
+ return common.Paginate(
+ p.Fields, call,
+ func(r *youtube.PlaylistListResponse) ([]*youtube.Playlist, string) {
+ return r.Items, r.NextPageToken
+ }, errGetPlaylist,
+ )
}
func (p *Playlist) List(writer io.Writer) error {
@@ -86,15 +89,18 @@ func (p *Playlist) List(writer io.Writer) error {
return err
}
- common.PrintList(p.Output, playlists, writer, table.Row{"ID", "Channel ID", "Title"}, func(pl *youtube.Playlist) table.Row {
- channelId := ""
- title := ""
- if pl.Snippet != nil {
- channelId = pl.Snippet.ChannelId
- title = pl.Snippet.Title
- }
- return table.Row{pl.Id, channelId, title}
- })
+ common.PrintList(
+ p.Output, playlists, writer, table.Row{"ID", "Channel ID", "Title"},
+ func(pl *youtube.Playlist) table.Row {
+ channelId := ""
+ title := ""
+ if pl.Snippet != nil {
+ channelId = pl.Snippet.ChannelId
+ title = pl.Snippet.Title
+ }
+ return table.Row{pl.Id, channelId, title}
+ },
+ )
return err
}
diff --git a/pkg/playlist/playlist_test.go b/pkg/playlist/playlist_test.go
index 72689a7..ff3d49f 100644
--- a/pkg/playlist/playlist_test.go
+++ b/pkg/playlist/playlist_test.go
@@ -286,21 +286,23 @@ func TestPlaylist_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "playlist-1", "snippet": {"title": "Playlist 1"}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
p := NewPlaylist(opts...)
@@ -362,11 +364,12 @@ func TestPlaylist_Get_Pagination(t *testing.T) {
}
func TestPlaylist_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "playlist-1",
@@ -377,9 +380,10 @@ func TestPlaylist_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
@@ -461,15 +465,17 @@ func TestPlaylist_Insert(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(`{"id": "new-playlist-id"}`))
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"id": "new-playlist-id"}`))
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
p := NewPlaylist(opts...)
@@ -575,25 +581,27 @@ func TestPlaylist_Update(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- if r.Method == "GET" {
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ if r.Method == "GET" {
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "playlist-id", "snippet": {"title": "Old Title"}, "status": {"privacyStatus": "public"}}
]
}`),
- )
- } else {
- _, _ = w.Write([]byte(`{"id": "playlist-id", "snippet": {"title": "Updated Title"}}`))
- }
- },
- ))
+ )
+ } else {
+ _, _ = w.Write([]byte(`{"id": "playlist-id", "snippet": {"title": "Updated Title"}}`))
+ }
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
p := NewPlaylist(opts...)
@@ -649,14 +657,16 @@ func TestPlaylist_Delete(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
p := NewPlaylist(opts...)
diff --git a/pkg/playlistImage/playlistImage.go b/pkg/playlistImage/playlistImage.go
index aa47ff9..55e0afe 100644
--- a/pkg/playlistImage/playlistImage.go
+++ b/pkg/playlistImage/playlistImage.go
@@ -68,9 +68,12 @@ func (pi *PlaylistImage) Get() ([]*youtube.PlaylistImage, error) {
call = call.OnBehalfOfContentOwnerChannel(pi.OnBehalfOfContentOwnerChannel)
}
- return common.Paginate(pi.Fields, call, func(r *youtube.PlaylistImageListResponse) ([]*youtube.PlaylistImage, string) {
- return r.Items, r.NextPageToken
- }, errGetPlaylistImage)
+ return common.Paginate(
+ pi.Fields, call,
+ func(r *youtube.PlaylistImageListResponse) ([]*youtube.PlaylistImage, string) {
+ return r.Items, r.NextPageToken
+ }, errGetPlaylistImage,
+ )
}
func (pi *PlaylistImage) List(writer io.Writer) error {
@@ -79,9 +82,13 @@ func (pi *PlaylistImage) List(writer io.Writer) error {
return err
}
- common.PrintList(pi.Output, playlistImages, writer, table.Row{"ID", "Kind", "Playlist ID", "Type"}, func(img *youtube.PlaylistImage) table.Row {
- return table.Row{img.Id, img.Kind, img.Snippet.PlaylistId, img.Snippet.Type}
- })
+ common.PrintList(
+ pi.Output, playlistImages, writer,
+ table.Row{"ID", "Kind", "Playlist ID", "Type"},
+ func(img *youtube.PlaylistImage) table.Row {
+ return table.Row{img.Id, img.Kind, img.Snippet.PlaylistId, img.Snippet.Type}
+ },
+ )
return err
}
@@ -121,7 +128,9 @@ func (pi *PlaylistImage) Insert(writer io.Writer) error {
return errors.Join(errInsertPlaylistImage, err)
}
- common.PrintResult(pi.Output, res, writer, "PlaylistImage inserted: %s\n", res.Id)
+ common.PrintResult(
+ pi.Output, res, writer, "PlaylistImage inserted: %s\n", res.Id,
+ )
return nil
}
@@ -173,7 +182,9 @@ func (pi *PlaylistImage) Update(writer io.Writer) error {
return errors.Join(errUpdatePlaylistImage, err)
}
- common.PrintResult(pi.Output, res, writer, "PlaylistImage updated: %s\n", res.Id)
+ common.PrintResult(
+ pi.Output, res, writer, "PlaylistImage updated: %s\n", res.Id,
+ )
return nil
}
diff --git a/pkg/playlistImage/playlistImage_test.go b/pkg/playlistImage/playlistImage_test.go
index a5d0dee..96c1d27 100644
--- a/pkg/playlistImage/playlistImage_test.go
+++ b/pkg/playlistImage/playlistImage_test.go
@@ -214,21 +214,23 @@ func TestPlaylistImage_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "image-1", "snippet": {"type": "default"}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
pi := NewPlaylistImage(opts...)
@@ -290,11 +292,12 @@ func TestPlaylistImage_Get_Pagination(t *testing.T) {
}
func TestPlaylistImage_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "image-1",
@@ -306,9 +309,10 @@ func TestPlaylistImage_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
@@ -470,15 +474,17 @@ func TestPlaylistImage_Insert(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(`{"id": "new-image-id"}`))
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"id": "new-image-id"}`))
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
pi := NewPlaylistImage(opts...)
@@ -567,25 +573,27 @@ func TestPlaylistImage_Update(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- if r.Method == "GET" {
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ if r.Method == "GET" {
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "image-id", "snippet": {"type": "default"}}
]
}`),
- )
- } else {
- _, _ = w.Write([]byte(`{"id": "image-id", "snippet": {"type": "hero"}}`))
- }
- },
- ))
+ )
+ } else {
+ _, _ = w.Write([]byte(`{"id": "image-id", "snippet": {"type": "hero"}}`))
+ }
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
pi := NewPlaylistImage(opts...)
@@ -646,14 +654,16 @@ func TestPlaylistImage_Delete(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
pi := NewPlaylistImage(opts...)
diff --git a/pkg/playlistItem/playlistItem.go b/pkg/playlistItem/playlistItem.go
index a575c13..8cb18d2 100644
--- a/pkg/playlistItem/playlistItem.go
+++ b/pkg/playlistItem/playlistItem.go
@@ -69,9 +69,12 @@ func (pi *PlaylistItem) Get() ([]*youtube.PlaylistItem, error) {
call = call.VideoId(pi.VideoId)
}
- return common.Paginate(pi.Fields, call, func(r *youtube.PlaylistItemListResponse) ([]*youtube.PlaylistItem, string) {
- return r.Items, r.NextPageToken
- }, errGetPlaylistItem)
+ return common.Paginate(
+ pi.Fields, call,
+ func(r *youtube.PlaylistItemListResponse) ([]*youtube.PlaylistItem, string) {
+ return r.Items, r.NextPageToken
+ }, errGetPlaylistItem,
+ )
}
func (pi *PlaylistItem) List(writer io.Writer) error {
@@ -80,26 +83,30 @@ func (pi *PlaylistItem) List(writer io.Writer) error {
return err
}
- common.PrintList(pi.Output, playlistItems, writer, table.Row{"ID", "Title", "Kind", "Resource ID"}, func(item *youtube.PlaylistItem) table.Row {
- title := ""
- kind := ""
- resourceId := ""
- if item.Snippet != nil {
- title = item.Snippet.Title
- if item.Snippet.ResourceId != nil {
- kind = item.Snippet.ResourceId.Kind
- switch kind {
- case "youtube#video":
- resourceId = item.Snippet.ResourceId.VideoId
- case "youtube#channel":
- resourceId = item.Snippet.ResourceId.ChannelId
- case "youtube#playlist":
- resourceId = item.Snippet.ResourceId.PlaylistId
+ common.PrintList(
+ pi.Output, playlistItems, writer,
+ table.Row{"ID", "Title", "Kind", "Resource ID"},
+ func(item *youtube.PlaylistItem) table.Row {
+ title := ""
+ kind := ""
+ resourceId := ""
+ if item.Snippet != nil {
+ title = item.Snippet.Title
+ if item.Snippet.ResourceId != nil {
+ kind = item.Snippet.ResourceId.Kind
+ switch kind {
+ case "youtube#video":
+ resourceId = item.Snippet.ResourceId.VideoId
+ case "youtube#channel":
+ resourceId = item.Snippet.ResourceId.ChannelId
+ case "youtube#playlist":
+ resourceId = item.Snippet.ResourceId.PlaylistId
+ }
}
}
- }
- return table.Row{item.Id, title, kind, resourceId}
- })
+ return table.Row{item.Id, title, kind, resourceId}
+ },
+ )
return err
}
@@ -151,7 +158,9 @@ func (pi *PlaylistItem) Insert(writer io.Writer) error {
return errors.Join(errInsertPlaylistItem, err)
}
- common.PrintResult(pi.Output, res, writer, "Playlist Item inserted: %s\n", res.Id)
+ common.PrintResult(
+ pi.Output, res, writer, "Playlist Item inserted: %s\n", res.Id,
+ )
return nil
}
@@ -192,7 +201,9 @@ func (pi *PlaylistItem) Update(writer io.Writer) error {
return errors.Join(errUpdatePlaylistItem, err)
}
- common.PrintResult(pi.Output, res, writer, "Playlist Item updated: %s\n", res.Id)
+ common.PrintResult(
+ pi.Output, res, writer, "Playlist Item updated: %s\n", res.Id,
+ )
return nil
}
diff --git a/pkg/playlistItem/playlistItem_test.go b/pkg/playlistItem/playlistItem_test.go
index 516db45..df3ec83 100644
--- a/pkg/playlistItem/playlistItem_test.go
+++ b/pkg/playlistItem/playlistItem_test.go
@@ -250,21 +250,23 @@ func TestPlaylistItem_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "item-1", "snippet": {"title": "Item 1", "resourceId": {"kind": "youtube#video", "videoId": "video-1"}}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
pi := NewPlaylistItem(opts...)
@@ -326,11 +328,12 @@ func TestPlaylistItem_Get_Pagination(t *testing.T) {
}
func TestPlaylistItem_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "item-1",
@@ -344,9 +347,10 @@ func TestPlaylistItem_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
@@ -520,15 +524,17 @@ func TestPlaylistItem_Insert(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(`{"id": "new-item-id"}`))
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"id": "new-item-id"}`))
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
pi := NewPlaylistItem(opts...)
@@ -614,25 +620,27 @@ func TestPlaylistItem_Update(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- if r.Method == "GET" {
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ if r.Method == "GET" {
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "item-id", "snippet": {"title": "Old Title"}, "status": {"privacyStatus": "public"}}
]
}`),
- )
- } else {
- _, _ = w.Write([]byte(`{"id": "item-id", "snippet": {"title": "Updated Title"}}`))
- }
- },
- ))
+ )
+ } else {
+ _, _ = w.Write([]byte(`{"id": "item-id", "snippet": {"title": "Updated Title"}}`))
+ }
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
pi := NewPlaylistItem(opts...)
@@ -690,14 +698,16 @@ func TestPlaylistItem_Delete(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
pi := NewPlaylistItem(opts...)
diff --git a/pkg/search/search.go b/pkg/search/search.go
index f6b56d7..1299213 100644
--- a/pkg/search/search.go
+++ b/pkg/search/search.go
@@ -151,9 +151,12 @@ func (s *Search) Get() ([]*youtube.SearchResult, error) {
call = call.VideoType(s.VideoType)
}
- return common.Paginate(s.Fields, call, func(r *youtube.SearchListResponse) ([]*youtube.SearchResult, string) {
- return r.Items, r.NextPageToken
- }, errGetSearch)
+ return common.Paginate(
+ s.Fields, call,
+ func(r *youtube.SearchListResponse) ([]*youtube.SearchResult, string) {
+ return r.Items, r.NextPageToken
+ }, errGetSearch,
+ )
}
func (s *Search) List(writer io.Writer) error {
@@ -162,18 +165,21 @@ func (s *Search) List(writer io.Writer) error {
return err
}
- common.PrintList(s.Output, results, writer, table.Row{"Kind", "Title", "Resource ID"}, func(r *youtube.SearchResult) table.Row {
- var resourceId string
- switch r.Id.Kind {
- case "youtube#video":
- resourceId = r.Id.VideoId
- case "youtube#channel":
- resourceId = r.Id.ChannelId
- case "youtube#playlist":
- resourceId = r.Id.PlaylistId
- }
- return table.Row{r.Id.Kind, r.Snippet.Title, resourceId}
- })
+ common.PrintList(
+ s.Output, results, writer, table.Row{"Kind", "Title", "Resource ID"},
+ func(r *youtube.SearchResult) table.Row {
+ var resourceId string
+ switch r.Id.Kind {
+ case "youtube#video":
+ resourceId = r.Id.VideoId
+ case "youtube#channel":
+ resourceId = r.Id.ChannelId
+ case "youtube#playlist":
+ resourceId = r.Id.PlaylistId
+ }
+ return table.Row{r.Id.Kind, r.Snippet.Title, resourceId}
+ },
+ )
return err
}
diff --git a/pkg/search/search_test.go b/pkg/search/search_test.go
index 752eab9..5d56b0b 100644
--- a/pkg/search/search_test.go
+++ b/pkg/search/search_test.go
@@ -236,9 +236,9 @@ func TestNewSearch(t *testing.T) {
},
},
want: &Search{
- Fields: &common.Fields{MaxResults: 25},
- Q: "golang tutorial",
- Order: "date",
+ Fields: &common.Fields{MaxResults: 25},
+ Q: "golang tutorial",
+ Order: "date",
RegionCode: "UK",
Types: []string{"video"},
},
@@ -412,21 +412,23 @@ func TestSearch_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": {"videoId": "video-1"}, "snippet": {"title": "Video 1"}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
s := NewSearch(opts...)
@@ -486,11 +488,12 @@ func TestSearch_Get_Pagination(t *testing.T) {
}
func TestSearch_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": {
@@ -503,9 +506,10 @@ func TestSearch_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
diff --git a/pkg/subscription/subscription.go b/pkg/subscription/subscription.go
index e2d59a7..3cae8cb 100644
--- a/pkg/subscription/subscription.go
+++ b/pkg/subscription/subscription.go
@@ -83,9 +83,12 @@ func (s *Subscription) Get() ([]*youtube.Subscription, error) {
call = call.Order(s.Order)
}
- return common.Paginate(s.Fields, call, func(r *youtube.SubscriptionListResponse) ([]*youtube.Subscription, string) {
- return r.Items, r.NextPageToken
- }, errGetSubscription)
+ return common.Paginate(
+ s.Fields, call,
+ func(r *youtube.SubscriptionListResponse) ([]*youtube.Subscription, string) {
+ return r.Items, r.NextPageToken
+ }, errGetSubscription,
+ )
}
func (s *Subscription) List(writer io.Writer) error {
@@ -94,18 +97,22 @@ func (s *Subscription) List(writer io.Writer) error {
return err
}
- common.PrintList(s.Output, subscriptions, writer, table.Row{"ID", "Kind", "Resource ID", "Channel Title"}, func(sub *youtube.Subscription) table.Row {
- var resourceId string
- switch sub.Snippet.ResourceId.Kind {
- case "youtube#video":
- resourceId = sub.Snippet.ResourceId.VideoId
- case "youtube#channel":
- resourceId = sub.Snippet.ResourceId.ChannelId
- case "youtube#playlist":
- resourceId = sub.Snippet.ResourceId.PlaylistId
- }
- return table.Row{sub.Id, sub.Snippet.ResourceId.Kind, resourceId, sub.Snippet.Title}
- })
+ common.PrintList(
+ s.Output, subscriptions, writer,
+ table.Row{"ID", "Kind", "Resource ID", "Channel Title"},
+ func(sub *youtube.Subscription) table.Row {
+ var resourceId string
+ switch sub.Snippet.ResourceId.Kind {
+ case "youtube#video":
+ resourceId = sub.Snippet.ResourceId.VideoId
+ case "youtube#channel":
+ resourceId = sub.Snippet.ResourceId.ChannelId
+ case "youtube#playlist":
+ resourceId = sub.Snippet.ResourceId.PlaylistId
+ }
+ return table.Row{sub.Id, sub.Snippet.ResourceId.Kind, resourceId, sub.Snippet.Title}
+ },
+ )
return err
}
@@ -130,7 +137,9 @@ func (s *Subscription) Insert(writer io.Writer) error {
return errors.Join(errInsertSubscription, err)
}
- common.PrintResult(s.Output, res, writer, "Subscription inserted: %s\n", res.Id)
+ common.PrintResult(
+ s.Output, res, writer, "Subscription inserted: %s\n", res.Id,
+ )
return nil
}
diff --git a/pkg/subscription/subscription_test.go b/pkg/subscription/subscription_test.go
index 2549f97..ed3b74f 100644
--- a/pkg/subscription/subscription_test.go
+++ b/pkg/subscription/subscription_test.go
@@ -315,21 +315,23 @@ func TestSubscription_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "sub-1", "snippet": {"title": "Subscription 1"}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
s := NewSubscription(opts...)
@@ -391,11 +393,12 @@ func TestSubscription_Get_Pagination(t *testing.T) {
}
func TestSubscription_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "sub-1",
@@ -409,9 +412,10 @@ func TestSubscription_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
@@ -533,15 +537,17 @@ func TestSubscription_Insert(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(`{"id": "new-sub-id"}`))
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"id": "new-sub-id"}`))
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
s := NewSubscription(opts...)
@@ -580,14 +586,16 @@ func TestSubscription_Delete(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
s := NewSubscription(opts...)
diff --git a/pkg/superChatEvent/superChatEvent.go b/pkg/superChatEvent/superChatEvent.go
index 07a7786..5fda717 100644
--- a/pkg/superChatEvent/superChatEvent.go
+++ b/pkg/superChatEvent/superChatEvent.go
@@ -44,9 +44,12 @@ func (s *SuperChatEvent) Get() ([]*youtube.SuperChatEvent, error) {
call = call.Hl(s.Hl)
}
- return common.Paginate(s.Fields, call, func(r *youtube.SuperChatEventListResponse) ([]*youtube.SuperChatEvent, string) {
- return r.Items, r.NextPageToken
- }, errGetSuperChatEvent)
+ return common.Paginate(
+ s.Fields, call,
+ func(r *youtube.SuperChatEventListResponse) ([]*youtube.SuperChatEvent, string) {
+ return r.Items, r.NextPageToken
+ }, errGetSuperChatEvent,
+ )
}
func (s *SuperChatEvent) List(writer io.Writer) error {
@@ -55,9 +58,12 @@ func (s *SuperChatEvent) List(writer io.Writer) error {
return err
}
- common.PrintList(s.Output, events, writer, table.Row{"ID", "Amount", "Comment", "Supporter"}, func(e *youtube.SuperChatEvent) table.Row {
- return table.Row{e.Id, e.Snippet.DisplayString, e.Snippet.CommentText, e.Snippet.SupporterDetails.DisplayName}
- })
+ common.PrintList(
+ s.Output, events, writer, table.Row{"ID", "Amount", "Comment", "Supporter"},
+ func(e *youtube.SuperChatEvent) table.Row {
+ return table.Row{e.Id, e.Snippet.DisplayString, e.Snippet.CommentText, e.Snippet.SupporterDetails.DisplayName}
+ },
+ )
return err
}
diff --git a/pkg/superChatEvent/superChatEvent_test.go b/pkg/superChatEvent/superChatEvent_test.go
index 2ea5ede..4f41157 100644
--- a/pkg/superChatEvent/superChatEvent_test.go
+++ b/pkg/superChatEvent/superChatEvent_test.go
@@ -151,21 +151,23 @@ func TestSuperChatEvent_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "event-1", "snippet": {"displayString": "¥500"}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
s := NewSuperChatEvent(opts...)
@@ -230,11 +232,12 @@ func TestSuperChatEvent_Get_Pagination(t *testing.T) {
}
func TestSuperChatEvent_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "event-1",
@@ -248,9 +251,10 @@ func TestSuperChatEvent_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
diff --git a/pkg/thumbnail/thumbnail.go b/pkg/thumbnail/thumbnail.go
index deef0ea..e4a63f0 100644
--- a/pkg/thumbnail/thumbnail.go
+++ b/pkg/thumbnail/thumbnail.go
@@ -50,7 +50,9 @@ func (t *Thumbnail) Set(writer io.Writer) error {
return errors.Join(errSetThumbnail, err)
}
- common.PrintResult(t.Output, res, writer, "Thumbnail set for video %s", t.VideoId)
+ common.PrintResult(
+ t.Output, res, writer, "Thumbnail set for video %s", t.VideoId,
+ )
return nil
}
diff --git a/pkg/thumbnail/thumbnail_test.go b/pkg/thumbnail/thumbnail_test.go
index 75151d2..4655d43 100644
--- a/pkg/thumbnail/thumbnail_test.go
+++ b/pkg/thumbnail/thumbnail_test.go
@@ -173,21 +173,23 @@ func TestThumbnail_Set(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"default": {"url": "https://example.com/thumb.jpg"}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
thumb := NewThumbnail(opts...)
diff --git a/pkg/video/video.go b/pkg/video/video.go
index d2791fb..d1e1c95 100644
--- a/pkg/video/video.go
+++ b/pkg/video/video.go
@@ -119,9 +119,12 @@ func (v *Video) Get() ([]*youtube.Video, error) {
call = call.OnBehalfOfContentOwner(v.OnBehalfOfContentOwner)
}
- return common.Paginate(v.Fields, call, func(r *youtube.VideoListResponse) ([]*youtube.Video, string) {
- return r.Items, r.NextPageToken
- }, errGetVideo)
+ return common.Paginate(
+ v.Fields, call,
+ func(r *youtube.VideoListResponse) ([]*youtube.Video, string) {
+ return r.Items, r.NextPageToken
+ }, errGetVideo,
+ )
}
func (v *Video) List(writer io.Writer) error {
@@ -130,19 +133,22 @@ func (v *Video) List(writer io.Writer) error {
return err
}
- common.PrintList(v.Output, videos, writer, table.Row{"ID", "Title", "Channel ID", "Views"}, func(video *youtube.Video) table.Row {
- title := ""
- channelId := ""
- var views uint64
- if video.Snippet != nil {
- title = video.Snippet.Title
- channelId = video.Snippet.ChannelId
- }
- if video.Statistics != nil {
- views = video.Statistics.ViewCount
- }
- return table.Row{video.Id, title, channelId, views}
- })
+ common.PrintList(
+ v.Output, videos, writer, table.Row{"ID", "Title", "Channel ID", "Views"},
+ func(video *youtube.Video) table.Row {
+ title := ""
+ channelId := ""
+ var views uint64
+ if video.Snippet != nil {
+ title = video.Snippet.Title
+ channelId = video.Snippet.ChannelId
+ }
+ if video.Statistics != nil {
+ views = video.Statistics.ViewCount
+ }
+ return table.Row{video.Id, title, channelId, views}
+ },
+ )
return err
}
diff --git a/pkg/video/video_test.go b/pkg/video/video_test.go
index b9c58b4..e0125d6 100644
--- a/pkg/video/video_test.go
+++ b/pkg/video/video_test.go
@@ -367,21 +367,23 @@ func TestVideo_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "video-1", "snippet": {"title": "Video 1"}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
v := NewVideo(opts...)
@@ -441,11 +443,12 @@ func TestVideo_Get_Pagination(t *testing.T) {
}
func TestVideo_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "video-1",
@@ -459,9 +462,10 @@ func TestVideo_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
@@ -645,15 +649,17 @@ func TestVideo_Insert(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(`{"id": "new-video-id", "snippet": {"title": "New Video"}, "status": {"privacyStatus": "public"}}`))
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"id": "new-video-id", "snippet": {"title": "New Video"}, "status": {"privacyStatus": "public"}}`))
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
v := NewVideo(opts...)
@@ -736,25 +742,27 @@ func TestVideo_Update(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- if r.Method == "GET" {
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ if r.Method == "GET" {
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "video-id", "snippet": {"title": "Old Title"}}
]
}`),
- )
- } else {
- _, _ = w.Write([]byte(`{"id": "video-id", "snippet": {"title": "Updated Title"}}`))
- }
- },
- ))
+ )
+ } else {
+ _, _ = w.Write([]byte(`{"id": "video-id", "snippet": {"title": "Updated Title"}}`))
+ }
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
v := NewVideo(opts...)
@@ -798,14 +806,16 @@ func TestVideo_Rate(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
v := NewVideo(opts...)
@@ -858,21 +868,23 @@ func TestVideo_GetRating(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"videoId": "video-id", "rating": "like"}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
v := NewVideo(opts...)
@@ -931,14 +943,16 @@ func TestVideo_Delete(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
v := NewVideo(opts...)
@@ -996,14 +1010,16 @@ func TestVideo_ReportAbuse(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
v := NewVideo(opts...)
diff --git a/pkg/videoAbuseReportReason/videoAbuseReportReason.go b/pkg/videoAbuseReportReason/videoAbuseReportReason.go
index f89faa2..881db35 100644
--- a/pkg/videoAbuseReportReason/videoAbuseReportReason.go
+++ b/pkg/videoAbuseReportReason/videoAbuseReportReason.go
@@ -60,9 +60,12 @@ func (va *VideoAbuseReportReason) List(writer io.Writer) error {
return err
}
- common.PrintList(va.Output, reasons, writer, table.Row{"ID", "Label"}, func(r *youtube.VideoAbuseReportReason) table.Row {
- return table.Row{r.Id, r.Snippet.Label}
- })
+ common.PrintList(
+ va.Output, reasons, writer, table.Row{"ID", "Label"},
+ func(r *youtube.VideoAbuseReportReason) table.Row {
+ return table.Row{r.Id, r.Snippet.Label}
+ },
+ )
return nil
}
diff --git a/pkg/videoAbuseReportReason/videoAbuseReportReason_test.go b/pkg/videoAbuseReportReason/videoAbuseReportReason_test.go
index 5e9ddb5..298f7be 100644
--- a/pkg/videoAbuseReportReason/videoAbuseReportReason_test.go
+++ b/pkg/videoAbuseReportReason/videoAbuseReportReason_test.go
@@ -125,21 +125,23 @@ func TestVideoAbuseReportReason_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "reason-1", "snippet": {"label": "Reason 1"}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
va := NewVideoAbuseReportReason(opts...)
@@ -163,11 +165,12 @@ func TestVideoAbuseReportReason_Get(t *testing.T) {
}
func TestVideoAbuseReportReason_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "reason-1",
@@ -177,9 +180,10 @@ func TestVideoAbuseReportReason_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
diff --git a/pkg/videoCategory/videoCategory.go b/pkg/videoCategory/videoCategory.go
index 786c2c8..4216ea6 100644
--- a/pkg/videoCategory/videoCategory.go
+++ b/pkg/videoCategory/videoCategory.go
@@ -65,9 +65,12 @@ func (vc *VideoCategory) List(writer io.Writer) error {
return err
}
- common.PrintList(vc.Output, categories, writer, table.Row{"ID", "Title", "Assignable"}, func(c *youtube.VideoCategory) table.Row {
- return table.Row{c.Id, c.Snippet.Title, c.Snippet.Assignable}
- })
+ common.PrintList(
+ vc.Output, categories, writer, table.Row{"ID", "Title", "Assignable"},
+ func(c *youtube.VideoCategory) table.Row {
+ return table.Row{c.Id, c.Snippet.Title, c.Snippet.Assignable}
+ },
+ )
return nil
}
diff --git a/pkg/videoCategory/videoCategory_test.go b/pkg/videoCategory/videoCategory_test.go
index eba3751..c7cdc45 100644
--- a/pkg/videoCategory/videoCategory_test.go
+++ b/pkg/videoCategory/videoCategory_test.go
@@ -151,21 +151,23 @@ func TestVideoCategory_Get(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{"id": "category-1", "snippet": {"title": "Category 1"}}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
vc := NewVideoCategory(opts...)
@@ -185,11 +187,12 @@ func TestVideoCategory_Get(t *testing.T) {
}
func TestVideoCategory_List(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write(
- []byte(`{
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(
+ []byte(`{
"items": [
{
"id": "category-1",
@@ -200,9 +203,10 @@ func TestVideoCategory_List(t *testing.T) {
}
]
}`),
- )
- },
- ))
+ )
+ },
+ ),
+ )
tests := []struct {
name string
diff --git a/pkg/watermark/watermark_test.go b/pkg/watermark/watermark_test.go
index d763e3b..59cd160 100644
--- a/pkg/watermark/watermark_test.go
+++ b/pkg/watermark/watermark_test.go
@@ -187,14 +187,16 @@ func TestWatermark_Set(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
w := NewWatermark(opts...)
@@ -253,14 +255,16 @@ func TestWatermark_Unset(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
- svc := common.NewTestService(t, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if tt.verify != nil {
- tt.verify(r)
- }
- w.WriteHeader(http.StatusNoContent)
- },
- ))
+ svc := common.NewTestService(
+ t, http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ if tt.verify != nil {
+ tt.verify(r)
+ }
+ w.WriteHeader(http.StatusNoContent)
+ },
+ ),
+ )
opts := append([]Option{WithService(svc)}, tt.opts...)
w := NewWatermark(opts...)
diff --git a/server.json b/server.json
index 28429b2..3b0cd82 100644
--- a/server.json
+++ b/server.json
@@ -6,7 +6,9 @@
"icons": [
{
"mimeType": "image/svg+xml",
- "sizes": ["any"],
+ "sizes": [
+ "any"
+ ],
"src": "https://raw.githubusercontent.com/eat-pray-ai/yutu/main/assets/yutu-ico.svg"
}
],
@@ -97,7 +99,12 @@
"isSecret": false,
"name": "YUTU_LOG_LEVEL",
"default": "INFO",
- "choices": ["DEBUG", "INFO", "WARNING", "ERROR"]
+ "choices": [
+ "DEBUG",
+ "INFO",
+ "WARNING",
+ "ERROR"
+ ]
}
]
}