-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (48 loc) · 1.47 KB
/
main.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
// Copyright 2023 Ainsley Clark. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
import (
"context"
"flag"
"fmt"
"github.com/ainsleyclark/errors"
"github.com/ainsleyclark/logger"
"github.com/ainsleyclark/stock-informer/config"
"github.com/ainsleyclark/stock-informer/inform"
"github.com/enescakir/emoji"
"log"
)
func main() {
// Info.
fmt.Printf("\n%v Welcome to Stock Informer\n\n", emoji.WavingHand)
// Create the logger.
opts := logger.NewOptions().
Service("Stock Informer").
Prefix("INFORMER").
DefaultStatus("LOG")
err := logger.New(context.Background(), opts)
if err != nil {
log.Fatalln(err)
}
// Obtain path flag.
path := flag.String("path", "", "Configuration file path")
flag.Parse()
if path == nil || *path == "" {
logger.WithError(errors.NewInvalid(errors.New("no path detected"), "Error, no path found, use -path=./config.yml for the configuration file.", "Configuration.Validate")).Fatal()
}
// Load the configuration file.
logger.Info("Loading Configuration")
cfg, err := config.Load(*path)
if err != nil {
logger.Fatal(err)
}
// Validate config.
// TODO - Move to separate config validation function.
if cfg.Pages == nil {
logger.WithError(errors.NewInvalid(errors.New("invalid configuration"), "Error, no pages found to scrape", "Configuration.Validate")).Fatal()
}
// Boot the cron job.
logger.Info("Booting Informer")
inform.New(cfg).Boot()
}