-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
72 lines (61 loc) · 2.19 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
package main
import (
"os"
"strings"
"github.com/openfaas-incubator/faas-memory/handlers"
"github.com/openfaas-incubator/faas-memory/types"
"github.com/openfaas-incubator/faas-memory/version"
faasProvider "github.com/openfaas/faas-provider"
"github.com/openfaas/faas-provider/logs"
providertypes "github.com/openfaas/faas-provider/types"
log "github.com/sirupsen/logrus"
)
func init() {
logFormat := os.Getenv("LOG_FORMAT")
logLevel := os.Getenv("LOG_LEVEL")
if strings.EqualFold(logFormat, "json") {
log.SetFormatter(&log.JSONFormatter{
FieldMap: log.FieldMap{
log.FieldKeyMsg: "message",
log.FieldKeyTime: "@timestamp",
},
TimestampFormat: "2006-01-02T15:04:05.999Z07:00",
})
} else {
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
}
if level, err := log.ParseLevel(logLevel); err == nil {
log.SetLevel(level)
}
}
func main() {
log.Infof("faas-memory version:%s. Last commit message: %s, commit SHA: %s'", version.BuildVersion(), version.GitCommitMessage, version.GitCommitSHA)
readConfig := types.ReadConfig{}
osEnv := types.OsEnv{}
cfg := readConfig.Read(osEnv)
faasProviderHandlers := providertypes.FaaSHandlers{
FunctionProxy: handlers.MakeProxy(),
DeleteHandler: handlers.MakeDeleteHandler(),
DeployHandler: handlers.MakeDeployHandler(),
FunctionReader: handlers.MakeFunctionReader(),
ReplicaReader: handlers.MakeReplicaReader(),
ReplicaUpdater: handlers.MakeReplicaUpdater(),
UpdateHandler: handlers.MakeUpdateHandler(),
HealthHandler: handlers.MakeHealthHandler(),
InfoHandler: handlers.MakeInfoHandler(version.BuildVersion(), version.GitCommitSHA),
SecretHandler: handlers.MakeSecretsHandler(),
LogHandler: logs.NewLogHandlerFunc(handlers.NewLogRequester(), cfg.WriteTimeout),
ListNamespaceHandler: handlers.NamespaceLister(),
}
faasProviderConfig := providertypes.FaaSConfig{
ReadTimeout: cfg.ReadTimeout,
WriteTimeout: cfg.WriteTimeout,
TCPPort: &cfg.Port,
EnableHealth: true,
EnableBasicAuth: false,
}
log.Infof("listening on port %d ...", cfg.Port)
faasProvider.Serve(&faasProviderHandlers, &faasProviderConfig)
}