-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.go
62 lines (53 loc) · 1.37 KB
/
stack.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
package stack
import (
"io/ioutil"
"runtime/debug"
"github.com/davecgh/go-spew/spew"
"github.com/kruglovmax/stack/pkg/consts"
"github.com/kruglovmax/stack/pkg/log"
"github.com/kruglovmax/stack/pkg/misc"
v1 "github.com/kruglovmax/stack/pkg/stack/v1/stack"
"github.com/kruglovmax/stack/pkg/types"
)
// RootStack instance
var rootStack types.Stack
// GetRootStack func
func GetRootStack() types.Stack {
return rootStack
}
// RunRootStack func
func RunRootStack(workdir string) {
var preConfig interface{}
stackFile := misc.FindStackFileInDir(workdir)
content, ioErr := ioutil.ReadFile(stackFile)
if ioErr != nil {
log.Logger.Debug().
Msg(string(debug.Stack()))
log.Logger.Fatal().
Str("file", stackFile).
Msg(ioErr.Error())
}
misc.LoadYAML(string(content), &preConfig)
switch preConfig.(type) {
case map[string]interface{}:
switch preConfig.(map[string]interface{})["api"] {
case "v1":
rootStack = new(v1.Stack)
rootStack.LoadFromFile(stackFile, nil)
rootStack.Start(nil)
default:
log.Logger.Debug().
Msg(string(debug.Stack()))
log.Logger.Fatal().
Str("file", stackFile).
Str("api", spew.Sdump(preConfig.(map[string]interface{})["api"])).
Msg(consts.MessageBadStackUnsupportedAPI)
}
default:
log.Logger.Debug().
Msg(string(debug.Stack()))
log.Logger.Fatal().
Str("file", stackFile).
Msg(consts.MessageBadStack)
}
}