mirror of
https://github.com/elyby/chrly.git
synced 2024-12-24 14:09:56 +05:30
f120064fe3
Added tests to jwt package Reworked redis backend implementation Skin repository now have methods to remove skins by user id or username
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"elyby/minecraft-skinsystem/auth"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
|
|
"elyby/minecraft-skinsystem/bootstrap"
|
|
"elyby/minecraft-skinsystem/db"
|
|
"elyby/minecraft-skinsystem/http"
|
|
)
|
|
|
|
var serveCmd = &cobra.Command{
|
|
Use: "serve",
|
|
Short: "Runs the system server skins",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
logger, err := bootstrap.CreateLogger(viper.GetString("statsd.addr"), viper.GetString("sentry.dsn"))
|
|
if err != nil {
|
|
log.Fatal(fmt.Printf("Cannot initialize logger: %v", err))
|
|
}
|
|
logger.Info("Logger successfully initialized")
|
|
|
|
storageFactory := db.StorageFactory{Config: viper.GetViper()}
|
|
|
|
logger.Info("Initializing skins repository")
|
|
skinsRepo, err := storageFactory.CreateFactory("redis").CreateSkinsRepository()
|
|
if err != nil {
|
|
logger.Emergency(fmt.Sprintf("Error on creating skins repo: %+v", err))
|
|
return
|
|
}
|
|
logger.Info("Skins repository successfully initialized")
|
|
|
|
logger.Info("Initializing capes repository")
|
|
capesRepo, err := storageFactory.CreateFactory("filesystem").CreateCapesRepository()
|
|
if err != nil {
|
|
logger.Emergency(fmt.Sprintf("Error on creating capes repo: %v", err))
|
|
return
|
|
}
|
|
logger.Info("Capes repository successfully initialized")
|
|
|
|
cfg := &http.Config{
|
|
ListenSpec: fmt.Sprintf("%s:%d", viper.GetString("server.host"), viper.GetInt("server.port")),
|
|
SkinsRepo: skinsRepo,
|
|
CapesRepo: capesRepo,
|
|
Logger: logger,
|
|
Auth: &auth.JwtAuth{},
|
|
}
|
|
|
|
if err := cfg.Run(); err != nil {
|
|
logger.Error(fmt.Sprintf("Error in main(): %v", err))
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
RootCmd.AddCommand(serveCmd)
|
|
}
|