-
Notifications
You must be signed in to change notification settings - Fork 1
/
container.go
72 lines (57 loc) · 1.78 KB
/
container.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
63
64
65
66
67
68
69
70
71
72
package app
import (
"os"
"github.com/cangyan/notion-youtube-feed/app/service/notion"
"github.com/cangyan/notion-youtube-feed/app/service/x_youtube"
)
type Container struct {
config *Config
xYouTubeService x_youtube.Service
notionService notion.Service
}
func (c *Container) Config() *Config {
if c.config == nil {
notionToken := os.Getenv("NOTION_TOKEN")
if notionToken == "" {
panic("NOTION_TOKEN not config")
}
notionDatabaseId := os.Getenv("NOTION_DATABASE_ID")
if notionDatabaseId == "" {
panic("NOTION_DATABASE_ID not config")
}
youtubeApiKey := os.Getenv("YOUTUBE_API_KEY")
if youtubeApiKey == "" {
panic("YOUTUBE_API_KEY not config")
}
youtubeClientId := os.Getenv("YOUTUBE_CLIENT_ID")
// if youtubeClientId == "" {
// panic("YOUTUBE_CLIENT_ID not config")
// }
youtubeClientSecret := os.Getenv("YOUTUBE_CLIENT_SECRET")
// if youtubeClientSecret == "" {
// panic("YOUTUBE_CLIENT_SECRET not config")
// }
youtubePlayListIds := os.Getenv("YOUTUBE_PLAYLIST_IDS")
c.config = &Config{
NotionToken: notionToken,
NotionDatabaseId: notionDatabaseId,
YouTubeApiKey: youtubeApiKey,
YouTubeClientId: youtubeClientId,
YouTubeClientSecret: youtubeClientSecret,
YouTubePlayListIds: youtubePlayListIds,
}
}
return c.config
}
func (c *Container) XYouTubeService() x_youtube.Service {
if c.xYouTubeService == nil {
c.xYouTubeService = x_youtube.NewService(c.Config().YouTubeApiKey, c.Config().YouTubeClientId, c.Config().YouTubeClientSecret, c.Config().YouTubePlayListIds)
}
return c.xYouTubeService
}
func (c *Container) NotionService() notion.Service {
if c.notionService == nil {
c.notionService = notion.NewService(c.Config().NotionToken, c.Config().NotionDatabaseId)
}
return c.notionService
}