diff --git a/CHANGELOG.md b/CHANGELOG.md index 140507df..78e3473e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Dev: Add some `pkg/utils/url.go` tests. (#525) - Dev: Make `IsSubdomainOf` variadic, making it easier for users of it to support multiple top level domains. (#526) - Dev: Use logger for skipping url message instead of fmt. (#554) +- Dev: Improve YoutTube resolver initialization logging. (#556) ## 2.0.2 diff --git a/internal/resolvers/youtube/initialize.go b/internal/resolvers/youtube/initialize.go index 1c2e48bd..12b33831 100644 --- a/internal/resolvers/youtube/initialize.go +++ b/internal/resolvers/youtube/initialize.go @@ -55,9 +55,15 @@ func NewYouTubeVideoResolvers(ctx context.Context, cfg config.APIConfig, pool db func Initialize(ctx context.Context, cfg config.APIConfig, pool db.Pool, resolvers *[]resolver.Resolver) { log := logger.FromContext(ctx) + if cfg.YoutubeApiKey == "" { + log.Warnw("[Config] youtube-api-key missing, won't do special responses for YouTube") + return + + } + youtubeClient, err := youtubeAPI.NewService(ctx, option.WithAPIKey(cfg.YoutubeApiKey)) if err != nil { - log.Warnw("[Config] youtube-api-key missing or otherwise misconfigured, won't do special responses for YouTube", + log.Warnw("[Config] Failed to create youtube client, won't do special responses for YouTube", "error", err, ) return diff --git a/internal/resolvers/youtube/initialize_test.go b/internal/resolvers/youtube/initialize_test.go index 38e2d261..cb6bb755 100644 --- a/internal/resolvers/youtube/initialize_test.go +++ b/internal/resolvers/youtube/initialize_test.go @@ -18,6 +18,10 @@ func TestInitialize(t *testing.T) { pool, err := pgxmock.NewPool() c.Assert(err, qt.IsNil) + // google.golang.org/api/youtube/v3 automatically + // uses this environment variable to initialize clients + c.Unsetenv("GOOGLE_APPLICATION_CREDENTIALS") + c.Run("No YouTube API key", func(c *qt.C) { cfg := config.APIConfig{ YoutubeApiKey: "",