diff --git a/lib/services/services.go b/lib/services/services.go index 6f0421b..d62f7ac 100644 --- a/lib/services/services.go +++ b/lib/services/services.go @@ -2,6 +2,9 @@ package services import ( "github.com/mediocregopher/radix.v2/redis" + "github.com/gorilla/mux" ) var Redis *redis.Client + +var Router *mux.Router diff --git a/minecraft-skinsystem.go b/minecraft-skinsystem.go index 64f03ca..c4ac5e0 100644 --- a/minecraft-skinsystem.go +++ b/minecraft-skinsystem.go @@ -2,6 +2,7 @@ package main import ( "log" + "runtime" "net/http" "github.com/gorilla/mux" @@ -11,23 +12,26 @@ import ( "elyby/minecraft-skinsystem/lib/services" ) -var client, redisErr = redis.Dial("tcp", "redis:6379") - func main() { + runtime.GOMAXPROCS(runtime.NumCPU()) + + client, redisErr := redis.Dial("tcp", "redis:6379") if redisErr != nil { log.Fatal("Redis unavailable") } - services.Redis = client - router := mux.NewRouter().StrictSlash(true) router.HandleFunc("/", routes.NotFound) - router.HandleFunc("/skins/{username}", routes.Skin).Methods("GET") - router.HandleFunc("/textures/{username}", routes.Textures).Methods("GET") - router.HandleFunc("/system/setSkin", routes.SetSkin).Methods("POST") // TODO: убрать этого, т.к. он стар + router.HandleFunc("/skins/{username}", routes.Skin).Methods("GET").Name("skins") + router.HandleFunc("/textures/{username}", routes.Textures).Methods("GET").Name("textures") + // TODO: убрать этого, т.к. он стар + router.HandleFunc("/system/setSkin", routes.SetSkin).Methods("POST") apiRouter := router.PathPrefix("/api").Subrouter() apiRouter.HandleFunc("/user/{username}/skin", routes.SetSkin).Methods("POST") + services.Redis = client + services.Router = router + log.Fatal(http.ListenAndServe(":80", router)) }