-
Notifications
You must be signed in to change notification settings - Fork 0
/
startup.go
executable file
·50 lines (47 loc) · 1.42 KB
/
startup.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
package module_server
import (
"context"
"errors"
"fmt"
"github.com/eru-tech/eru/eru-alerts/module_store"
logs "github.com/eru-tech/eru/eru-logs/eru-logs"
"os"
"strings"
)
const StoreTableName = "erualerts_config"
func StartUp() (module_store.ModuleStoreI, error) {
logs.WithContext(context.Background()).Debug("StartUp - Start")
storeType := strings.ToUpper(os.Getenv("STORE_TYPE"))
if storeType == "" {
storeType = "STANDALONE"
logs.WithContext(context.Background()).Info("STORE_TYPE environment variable not found - loading default standlone store")
}
var myStore module_store.ModuleStoreI
var err error
switch storeType {
case "POSTGRES":
myStore = new(module_store.ModuleDbStore)
myStore.SetDbType(storeType)
myStore.SetStoreTableName(StoreTableName)
case "STANDALONE":
// myStore, err = store.LoadStoreFromFile()
myStore = new(module_store.ModuleFileStore)
if err != nil {
logs.WithContext(context.Background()).Error(err.Error())
return nil, err
}
default:
err = errors.New(fmt.Sprint("Invalid STORE_TYPE ", storeType))
logs.WithContext(context.Background()).Error(err.Error())
return nil, err
}
storeBytes, err := myStore.GetStoreByteArray("")
if err == nil {
//err = json.Unmarshal(storeBytes, myStore)
module_store.UnMarshalStore(context.Background(), storeBytes, myStore)
} else {
logs.WithContext(context.Background()).Error(err.Error())
}
//s.Store = myStore
return myStore, err
}