2017-06-30 21:10:25 +05:30
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2018-02-15 16:50:17 +05:30
|
|
|
"strings"
|
2017-06-30 21:10:25 +05:30
|
|
|
|
2023-12-13 21:59:12 +05:30
|
|
|
. "github.com/defval/di"
|
2017-06-30 21:10:25 +05:30
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
2020-01-03 03:21:57 +05:30
|
|
|
|
2024-02-01 12:42:34 +05:30
|
|
|
"ely.by/chrly/internal/di"
|
|
|
|
"ely.by/chrly/internal/http"
|
|
|
|
"ely.by/chrly/internal/version"
|
2017-06-30 21:10:25 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
var RootCmd = &cobra.Command{
|
2018-02-15 02:19:22 +05:30
|
|
|
Use: "chrly",
|
2024-02-01 12:28:26 +05:30
|
|
|
Short: "Implementation of the Minecraft skins system server",
|
2020-01-03 03:21:57 +05:30
|
|
|
Version: version.Version(),
|
2017-06-30 21:10:25 +05:30
|
|
|
}
|
|
|
|
|
2020-04-19 05:01:09 +05:30
|
|
|
func shouldGetContainer() *Container {
|
|
|
|
container, err := di.New()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return container
|
|
|
|
}
|
|
|
|
|
2024-02-07 18:59:52 +05:30
|
|
|
func startServer(modules ...string) error {
|
2020-04-19 05:01:09 +05:30
|
|
|
container := shouldGetContainer()
|
|
|
|
|
|
|
|
var config *viper.Viper
|
|
|
|
err := container.Resolve(&config)
|
|
|
|
if err != nil {
|
2024-02-07 18:59:52 +05:30
|
|
|
return err
|
2020-04-19 05:01:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
config.Set("modules", modules)
|
|
|
|
|
|
|
|
err = container.Invoke(http.StartServer)
|
|
|
|
if err != nil {
|
2024-02-07 18:59:52 +05:30
|
|
|
return err
|
2020-04-19 05:01:09 +05:30
|
|
|
}
|
2024-02-07 18:59:52 +05:30
|
|
|
|
|
|
|
return nil
|
2020-04-19 05:01:09 +05:30
|
|
|
}
|
|
|
|
|
2018-01-24 04:09:40 +05:30
|
|
|
func init() {
|
2017-06-30 21:10:25 +05:30
|
|
|
cobra.OnInitialize(initConfig)
|
|
|
|
}
|
|
|
|
|
|
|
|
func initConfig() {
|
2017-08-15 03:13:31 +05:30
|
|
|
viper.AutomaticEnv()
|
2018-02-15 16:50:17 +05:30
|
|
|
replacer := strings.NewReplacer(".", "_")
|
|
|
|
viper.SetEnvKeyReplacer(replacer)
|
2017-06-30 21:10:25 +05:30
|
|
|
}
|