-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud_fn.go
56 lines (50 loc) · 1.22 KB
/
cloud_fn.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
package main
import (
"flag"
"fmt"
"os"
"goct/internal/cmd"
"goct/internal/logger"
)
const (
defaultConfigName = "config.yaml"
defaultStatePath = "state"
defaultModeEnv = "RUN_MODE"
)
func processFlags() (string, error) {
cwd, err := os.Getwd()
if err != nil {
return "", err
}
var configPath = flag.String("config", cwd+"/"+defaultConfigName, "relative path to config")
// var statePath = flag.String("state", cwd+"/"+defaultStatePath, "relative path to state")
if os.Getenv(defaultModeEnv) == "CLOUD_FUNC" {
// TODO: better solution for cloud funcs
cpath := os.Getenv("CONFIG_PATH")
configPath = &cpath
// spath := os.Getenv("STATE_PATH")
// statePath = &spath
} else {
flag.Parse()
}
return cwd + "/" + *configPath, nil
}
func CloudFuncHandler() error {
logger.Infof("running mode: %s", os.Getenv(defaultModeEnv))
cfgPath, err := processFlags()
if err != nil {
fmt.Fprintf(os.Stdout, "Unable to process flags %s", err.Error())
os.Exit(1)
}
cmd.Do(cfgPath)
return nil
}
func main() {
logger.Infof("running mode: %s", os.Getenv(defaultModeEnv))
cfgPath, err := processFlags()
if err != nil {
fmt.Fprintf(os.Stdout, "Unable to process flags %s", err.Error())
os.Exit(1)
}
cmd.Do(cfgPath)
}