forked from raystack/optimus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (62 loc) · 1.49 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
71
72
73
package main
import (
"errors"
"fmt"
"log"
"math/rand"
"os"
"strings"
"time"
"github.com/hashicorp/go-hclog"
"github.com/odpf/optimus/plugin"
hPlugin "github.com/hashicorp/go-plugin"
"github.com/odpf/optimus/cmd"
"github.com/odpf/optimus/config"
lg "github.com/odpf/optimus/core/logger"
_ "github.com/odpf/optimus/ext/datastore"
"github.com/odpf/optimus/models"
_ "github.com/odpf/optimus/plugin"
)
var (
errRequestFail = errors.New("🔥 unable to complete request successfully")
)
func main() {
rand.Seed(time.Now().UTC().UnixNano())
configuration, err := config.InitOptimus()
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
os.Exit(1)
}
pluginLogLevel := hclog.Info
if configuration.GetLog().Level != "" {
lg.Init(configuration.GetLog().Level)
if strings.ToLower(configuration.GetLog().Level) == "debug" {
pluginLogLevel = hclog.Debug
}
} else {
lg.Init(lg.INFO)
}
// discover and load plugins
if err := plugin.Initialize(hclog.New(&hclog.LoggerOptions{
Name: "optimus",
Output: os.Stdout,
Level: pluginLogLevel,
})); err != nil {
hPlugin.CleanupClients()
fmt.Printf("ERROR: %s\n", err.Error())
os.Exit(1)
}
// Make sure we clean up any managed plugins at the end of this
defer hPlugin.CleanupClients()
command := cmd.New(
log.New(os.Stderr, "", 0),
configuration,
models.PluginRegistry,
models.DatastoreRegistry,
)
if err := command.Execute(); err != nil {
hPlugin.CleanupClients()
fmt.Println(errRequestFail)
os.Exit(1)
}
}