This repository has been archived by the owner on Jun 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwire_gen.go
62 lines (51 loc) · 1.7 KB
/
wire_gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Code generated by Wire. DO NOT EDIT.
//go:generate go run github.com/google/wire/cmd/wire
//go:build !wireinject
// +build !wireinject
package main
import (
"context"
"github.com/SkYNewZ/youtube-sorter/internal/auth"
"github.com/google/wire"
"github.com/sirupsen/logrus"
oauth2_2 "golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"google.golang.org/api/oauth2/v2"
"google.golang.org/api/option"
"google.golang.org/api/youtube/v3"
"os"
"time"
)
// Injectors from wire.go:
func initializeSorter(ctx context.Context, interval time.Duration, logger logrus.FieldLogger, filename string, playlistID PlaylistID, cacheDirectory auth.CacheDirectory) (*Sorter, error) {
v, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
config, err := provideConfig(v)
if err != nil {
return nil, err
}
tokenSource := auth.NewTokenSource(ctx, config, logger, cacheDirectory)
v2 := provideOptions(tokenSource)
service, err := youtube.NewService(ctx, v2...)
if err != nil {
return nil, err
}
oauth2Service, err := oauth2.NewService(ctx, v2...)
if err != nil {
return nil, err
}
sorter := NewSorter(interval, service, oauth2Service, logger, playlistID)
return sorter, nil
}
// wire.go:
var youtubeServiceProviderSet = wire.NewSet(youtube.NewService)
var oauth2ServiceProviderSet = wire.NewSet(oauth2.NewService)
var tokenSourceProviderSet = wire.NewSet(os.ReadFile, provideConfig, auth.NewTokenSource)
func provideOptions(tokenSource oauth2_2.TokenSource) []option.ClientOption {
return []option.ClientOption{option.WithTokenSource(tokenSource)}
}
func provideConfig(jsonKey []byte) (*oauth2_2.Config, error) {
return google.ConfigFromJSON(jsonKey, youtube.YoutubeScope, oauth2.UserinfoEmailScope)
}