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
|
|
|
|
2018-01-23 21:13:37 +05:30
|
|
|
"elyby/minecraft-skinsystem/auth"
|
|
|
|
|
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-14 23:36:22 +05:30
|
|
|
"elyby/minecraft-skinsystem/db"
|
2017-08-20 03:52:42 +05:30
|
|
|
"elyby/minecraft-skinsystem/http"
|
2017-06-30 21:10:25 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
var serveCmd = &cobra.Command{
|
|
|
|
Use: "serve",
|
2018-02-15 02:19:22 +05:30
|
|
|
Short: "Starts http handler for the skins system",
|
2017-06-30 21:10:25 +05:30
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2017-08-27 20:40:03 +05:30
|
|
|
logger, err := bootstrap.CreateLogger(viper.GetString("statsd.addr"), viper.GetString("sentry.dsn"))
|
2017-08-16 17:53:03 +05:30
|
|
|
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
|
|
|
|
2017-08-20 03:52:42 +05:30
|
|
|
cfg := &http.Config{
|
2017-08-14 23:36:22 +05:30
|
|
|
ListenSpec: fmt.Sprintf("%s:%d", viper.GetString("server.host"), viper.GetInt("server.port")),
|
2018-01-23 21:13:37 +05:30
|
|
|
SkinsRepo: skinsRepo,
|
|
|
|
CapesRepo: capesRepo,
|
|
|
|
Logger: logger,
|
2018-02-15 16:50:17 +05:30
|
|
|
Auth: &auth.JwtAuth{Key: []byte(viper.GetString("chrly.secret"))},
|
2017-06-30 21:10:25 +05:30
|
|
|
}
|
|
|
|
|
2017-08-20 03:52:42 +05:30
|
|
|
if err := cfg.Run(); err != nil {
|
2017-06-30 21:10:25 +05:30
|
|
|
logger.Error(fmt.Sprintf("Error in main(): %v", err))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RootCmd.AddCommand(serveCmd)
|
2018-02-15 16:50:17 +05:30
|
|
|
viper.SetDefault("server.host", "")
|
|
|
|
viper.SetDefault("server.port", 80)
|
|
|
|
viper.SetDefault("storage.redis.host", "localhost")
|
|
|
|
viper.SetDefault("storage.redis.port", 6379)
|
|
|
|
viper.SetDefault("storage.redis.poll", 10)
|
|
|
|
viper.SetDefault("storage.filesystem.basePath", "data")
|
|
|
|
viper.SetDefault("storage.filesystem.capesDirName", "capes")
|
2017-06-30 21:10:25 +05:30
|
|
|
}
|