Skip to content

Commit a67f991

Browse files
committed
changes to notify
1 parent ccbb9a7 commit a67f991

3 files changed

Lines changed: 11 additions & 12 deletions

File tree

src/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ type DiscordNotif struct {
151151
}
152152

153153
type HttpNotif struct {
154-
ReceiverURLs []string `env:"HTTP_RECEIVER"`
154+
ReceiverURL string `env:"HTTP_RECEIVER"`
155155
}
156156
func (cfg *Config) ReadEnv() {
157157

src/logging/logging.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ import (
77
)
88

99

10-
func Init(level string) {
11-
handler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
10+
func Init(level string, notifyClient NotificationClient) {
11+
baseHandler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
1212
Level: getLogLevel(level),
13+
AddSource: true,
1314
})
15+
16+
handler := &notifyHandler{
17+
handler: baseHandler,
18+
notify: notifyClient,
19+
}
1420
logger := slog.New(handler)
1521
slog.SetDefault(logger)
1622
}

src/main/main.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"explo/src/logging"
5-
"fmt"
65
"log"
76
"log/slog"
87
"os"
@@ -29,7 +28,8 @@ func initHttpClient() *util.HttpClient {
2928
// Inits debug, gets playlist name, if needed, handles deprecation
3029
func setup(cfg *config.Config) {
3130
cfg.HandleDeprecation()
32-
logging.Init(cfg.LogLevel)
31+
notifyClient := logging.InitNotify(cfg.NotifyCfg)
32+
logging.Init(cfg.LogLevel, notifyClient)
3333
cfg.GenPlaylistName()
3434
}
3535

@@ -44,25 +44,21 @@ func main() {
4444
slog.Info("Starting Explo...")
4545

4646
httpClient := initHttpClient()
47-
notifyClient := logging.InitNotify(cfg.NotifyCfg)
4847
client, err := client.NewClient(&cfg)
4948
if err != nil {
5049
slog.Error(err.Error())
51-
notifyClient.SendNotification(err.Error())
5250
os.Exit(1)
5351
}
5452
discovery := discovery.NewDiscoverer(cfg.DiscoveryCfg, httpClient)
5553
downloader, err := downloader.NewDownloader(&cfg.DownloadCfg, httpClient, cfg.Flags.ExcludeLocal)
5654
if err != nil {
5755
slog.Error(err.Error())
58-
notifyClient.SendNotification(err.Error())
5956
os.Exit(1)
6057
}
6158

6259
tracks, err := discovery.Discover()
6360
if err != nil {
6461
slog.Error(err.Error())
65-
notifyClient.SendNotification(err.Error())
6662
os.Exit(1)
6763
}
6864
if !cfg.Persist {
@@ -84,16 +80,13 @@ func main() {
8480
downloader.StartDownload(&tracks)
8581
if len(tracks) == 0 {
8682
slog.Error("couldn't download any tracks")
87-
notifyClient.SendNotification("couldn't download any tracks")
8883
os.Exit(1)
8984
}
9085
}
9186

9287
if err := client.CreatePlaylist(tracks); err != nil {
9388
slog.Warn(err.Error())
94-
notifyClient.SendNotification(err.Error())
9589
} else {
9690
slog.Info("playlist created successfully", "system", cfg.System, "name", cfg.ClientCfg.PlaylistName)
97-
notifyClient.SendNotification(fmt.Sprintf("%s playlist created in %s", cfg.ClientCfg.PlaylistName, cfg.System))
9891
}
9992
}

0 commit comments

Comments
 (0)