feat: Component
This commit is contained in:
1 parent
a3ab13975a
commit
e03e3e1514
4 files changed
+52
-49
No files matched your search
@@ -4,7 +4,6 @@ import (
|
||||
"go.uber.org/zap"
|
||||
"os"
|
||||
"universe.mrlokop.dev/core/config"
|
||||
"universe.mrlokop.dev/core/fs"
|
||||
"universe.mrlokop.dev/core/modules"
|
||||
)
|
||||
|
||||
@@ -18,17 +17,6 @@ var (
|
||||
|
||||
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")
|
||||
})
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"go.uber.org/fx"
|
||||
"os"
|
||||
"time"
|
||||
uc "universe.mrlokop.dev/core/config"
|
||||
"universe.mrlokop.dev/core/fs"
|
||||
)
|
||||
|
||||
func StartApplication(
|
||||
runDirectory string,
|
||||
) error {
|
||||
if runDirectory == "" {
|
||||
runEnv := os.Getenv("UNIVERSE_RUN_PATH")
|
||||
if runEnv == "" {
|
||||
runDirectory = "."
|
||||
} else {
|
||||
runDirectory = runEnv
|
||||
}
|
||||
}
|
||||
|
||||
cfg := new(uc.UniverseConfig)
|
||||
err := uc.LoadConfigFromDirectory(runDirectory, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
app := NewUniverseApplication(cfg)
|
||||
|
||||
baseModule, err := Module.Create("$base", make(map[string]interface{}))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
app.WithOption(
|
||||
fx.StartTimeout(10*time.Minute),
|
||||
fx.Supply(cfg),
|
||||
fx.Provide(func() RunPath {
|
||||
return fs.System.INodeAt(runDirectory)
|
||||
}),
|
||||
baseModule,
|
||||
)
|
||||
|
||||
return app.Run()
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"go.uber.org/fx"
|
||||
"log"
|
||||
"time"
|
||||
ua "universe.mrlokop.dev/core/app"
|
||||
uc "universe.mrlokop.dev/core/config"
|
||||
)
|
||||
|
||||
func main() {
|
||||
runDirectory := "run"
|
||||
|
||||
cfg := new(uc.UniverseConfig)
|
||||
err := uc.LoadConfigFromDirectory(runDirectory, cfg)
|
||||
if err != nil {
|
||||
log.Fatalf("Error loading config: %v", err)
|
||||
}
|
||||
|
||||
app := ua.NewUniverseApplication(cfg)
|
||||
|
||||
create, err := ua.Module.Create("$base", make(map[string]interface{}))
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating base module: %v", err)
|
||||
}
|
||||
|
||||
app.WithOption(
|
||||
fx.StartTimeout(10*time.Minute),
|
||||
fx.Supply(cfg),
|
||||
create,
|
||||
)
|
||||
|
||||
err = app.Run()
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package modules
|
||||
|
||||
type Component interface {
|
||||
ComponentKind() string
|
||||
ComponentId() string
|
||||
}
|
||||
Reference in new issue
Block a user