2017-06-30 21:10:25 +05:30
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2017-08-10 05:44:28 +05:30
|
|
|
"fmt"
|
2017-08-16 17:53:03 +05:30
|
|
|
"log"
|
2017-06-30 21:10:25 +05:30
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2017-08-14 23:36:22 +05:30
|
|
|
"github.com/spf13/viper"
|
2017-08-10 05:44:28 +05:30
|
|
|
|
2017-08-16 17:53:03 +05:30
|
|
|
"elyby/minecraft-skinsystem/bootstrap"
|
2017-08-10 05:44:28 +05:30
|
|
|
"elyby/minecraft-skinsystem/daemon"
|
2017-08-14 23:36:22 +05:30
|
|
|
"elyby/minecraft-skinsystem/db"
|
2017-08-10 05:44:28 +05:30
|
|
|
"elyby/minecraft-skinsystem/ui"
|
2017-06-30 21:10:25 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
var serveCmd = &cobra.Command{
|
|
|
|
Use: "serve",
|
2017-08-15 03:13:31 +05:30
|
|
|
Short: "Runs the system server skins",
|
2017-06-30 21:10:25 +05:30
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2017-08-16 17:53:03 +05:30
|
|
|
logger, err := bootstrap.CreateLogger(viper.GetString("statsd.addr"))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(fmt.Printf("Cannot initialize logger: %v", err))
|
|
|
|
}
|
|
|
|
logger.Info("Logger successfully initialized")
|
2017-06-30 21:10:25 +05:30
|
|
|
|
2017-08-14 23:36:22 +05:30
|
|
|
storageFactory := db.StorageFactory{Config: viper.GetViper()}
|
|
|
|
|
|
|
|
logger.Info("Initializing skins repository")
|
|
|
|
skinsRepo, err := storageFactory.CreateFactory("redis").CreateSkinsRepository()
|
2017-06-30 21:10:25 +05:30
|
|
|
if err != nil {
|
2017-08-14 23:36:22 +05:30
|
|
|
logger.Emergency(fmt.Sprintf("Error on creating skins repo: %+v", err))
|
2017-06-30 21:10:25 +05:30
|
|
|
return
|
|
|
|
}
|
2017-08-14 23:36:22 +05:30
|
|
|
logger.Info("Skins repository successfully initialized")
|
2017-06-30 21:10:25 +05:30
|
|
|
|
2017-08-14 23:36:22 +05:30
|
|
|
logger.Info("Initializing capes repository")
|
|
|
|
capesRepo, err := storageFactory.CreateFactory("filesystem").CreateCapesRepository()
|
2017-06-30 21:10:25 +05:30
|
|
|
if err != nil {
|
|
|
|
logger.Emergency(fmt.Sprintf("Error on creating capes repo: %v", err))
|
|
|
|
return
|
|
|
|
}
|
2017-08-14 23:36:22 +05:30
|
|
|
logger.Info("Capes repository successfully initialized")
|
2017-06-30 21:10:25 +05:30
|
|
|
|
|
|
|
cfg := &daemon.Config{
|
2017-08-14 23:36:22 +05:30
|
|
|
ListenSpec: fmt.Sprintf("%s:%d", viper.GetString("server.host"), viper.GetInt("server.port")),
|
2017-06-30 21:10:25 +05:30
|
|
|
SkinsRepo: skinsRepo,
|
|
|
|
CapesRepo: capesRepo,
|
|
|
|
Logger: logger,
|
|
|
|
UI: ui.Config{},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := daemon.Run(cfg); err != nil {
|
|
|
|
logger.Error(fmt.Sprintf("Error in main(): %v", err))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RootCmd.AddCommand(serveCmd)
|
|
|
|
}
|