feat: Initial
This commit is contained in:
commit
f0abca60db
26 files changed
+1112
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"go.mrlokop.dev/universe/core/config"
|
||||
"go.mrlokop.dev/universe/core/fs"
|
||||
"go.mrlokop.dev/universe/core/modules"
|
||||
"go.uber.org/zap"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
Module = modules.SimpleModule("universe:core", func(context modules.ModuleFactoryContext) error {
|
||||
context.Invoke(func(log *zap.Logger, info *Info, env AppEnvType) {
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
hostname = "unknown"
|
||||
}
|
||||
|
||||
log.Sugar().Infof("Starting %s on %s, pid=%v, env=%s", info.ServiceName, hostname, os.Getpid(), env)
|
||||
})
|
||||
context.Provide(func(env AppEnvType) RunPath {
|
||||
if env == AppEnvTypeDevelopment {
|
||||
return fs.System.INodeAt("run")
|
||||
}
|
||||
|
||||
runEnv := os.Getenv("UNIVERSE_RUN_PATH")
|
||||
if runEnv == "" {
|
||||
return fs.System.INodeAt(".")
|
||||
}
|
||||
return fs.System.INodeAt(runEnv)
|
||||
})
|
||||
context.Provide(func(path RunPath) StoragePath {
|
||||
return path.Join("storage")
|
||||
})
|
||||
context.Provide(provideEnv)
|
||||
context.Provide(provideAppInfo)
|
||||
context.Provide(func(app Application) *config.UniverseConfig {
|
||||
return app.Config()
|
||||
})
|
||||
context.Provide(func(env AppEnvType) *zap.Logger {
|
||||
if env == AppEnvTypeDevelopment {
|
||||
config := zap.NewDevelopmentConfig()
|
||||
config.OutputPaths = []string{"stdout"}
|
||||
return zap.Must(config.Build(
|
||||
zap.WithCaller(true),
|
||||
))
|
||||
}
|
||||
|
||||
return zap.Must(zap.NewProduction())
|
||||
})
|
||||
return nil
|
||||
})
|
||||
)
|
||||
Reference in new issue
Block a user