-
Notifications
You must be signed in to change notification settings - Fork 53
/
main.go
70 lines (54 loc) · 1.9 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"embed"
"github.com/scratchdata/scratchdata/pkg/api"
"github.com/scratchdata/scratchdata/pkg/app"
"github.com/scratchdata/scratchdata/pkg/config"
"github.com/scratchdata/scratchdata/pkg/storage"
"os"
"github.com/scratchdata/scratchdata/pkg/datasink"
"github.com/scratchdata/scratchdata/pkg/destinations"
"github.com/ilyakaznacheev/cleanenv"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
//go:embed config.yaml
var defaultConfig embed.FS
func main() {
// Set default log format before we read config
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger()
var configOptions config.ScratchDataConfig
useDefaultConfig := len(os.Args) == 1
if useDefaultConfig {
log.Info().Msg("No config file specified, using local default values")
f, err := defaultConfig.Open("config.yaml")
if err != nil {
log.Fatal().Err(err).Msg("Unable to parse open config")
}
err = cleanenv.ParseYAML(f, &configOptions)
if err != nil {
log.Fatal().Err(err).Msg("Unable to read config")
}
f.Close()
} else {
err := cleanenv.ReadConfig(os.Args[1], &configOptions)
if err != nil {
log.Fatal().Err(err).Msg("Unable to read configuration file")
}
}
storageServices, err := storage.New(configOptions)
if err != nil {
log.Fatal().Err(err).Msg("Unable to initialize storage")
}
destinationManager := destinations.NewDestinationManager(storageServices)
dataSink, err := datasink.NewDataSink(configOptions.DataSink, storageServices)
if err != nil {
log.Fatal().Err(err).Msg("Unable to set up data sink")
}
apiFunctions, err := api.NewScratchDataAPI(storageServices, destinationManager, dataSink, configOptions)
if err != nil {
log.Fatal().Err(err).Msg("Unable to build API")
}
mux := api.CreateMux(storageServices, apiFunctions, configOptions, destinationManager)
app.Run(configOptions, storageServices, destinationManager, dataSink, mux)
}