Удалено логирование ожидаемой ошибки с несуществованием скина в redis.

This commit is contained in:
ErickSkrauch 2016-08-26 23:45:55 +03:00
parent 89ea6e5ee8
commit 4bdab704a5
4 changed files with 27 additions and 5 deletions

11
lib/data/DataNotFound.go Normal file
View File

@ -0,0 +1,11 @@
package data
import "fmt"
type DataNotFound struct {
Who string
}
func (e DataNotFound) Error() string {
return fmt.Sprintf("Skin data not found. Required username \"%v\"", e.Who)
}

View File

@ -6,6 +6,8 @@ import (
"elyby/minecraft-skinsystem/lib/services"
"elyby/minecraft-skinsystem/lib/tools"
"github.com/mediocregopher/radix.v2/redis"
)
type SkinItem struct {
@ -25,14 +27,17 @@ func (s *SkinItem) Save() {
func FindRecord(username string) (SkinItem, error) {
var record SkinItem;
result, err := services.RedisPool.Cmd("GET", tools.BuildKey(username)).Str();
response := services.RedisPool.Cmd("GET", tools.BuildKey(username));
if (response.IsType(redis.Nil)) {
return record, DataNotFound{username}
}
result, err := response.Str()
if (err == nil) {
decodeErr := json.Unmarshal([]byte(result), &record)
if (decodeErr != nil) {
log.Println("Cannot decode record data")
}
} else {
log.Println("Error on request user data: " + err.Error())
}
return record, err

View File

@ -1,6 +1,7 @@
package routes
import (
"log"
"net/http"
"github.com/gorilla/mux"
@ -10,6 +11,7 @@ import (
func Cape(w http.ResponseWriter, r *http.Request) {
username := tools.ParseUsername(mux.Vars(r)["username"])
log.Println("request cape for username " + username)
http.Redirect(w, r, "http://skins.minecraft.net/MinecraftCloaks/" + username + ".png", 301)
}

View File

@ -17,12 +17,16 @@ import (
const redisString string = "redis:6379"
func main() {
log.Println("Starting...")
runtime.GOMAXPROCS(runtime.NumCPU())
pool, redisErr := pool.New("tcp", redisString, 10)
log.Println("Connecting to redis")
redisPool, redisErr := pool.New("tcp", redisString, 10)
if redisErr != nil {
log.Fatal("Redis unavailable")
}
log.Println("Connected to redis")
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/skins/{username}", routes.Skin).Methods("GET").Name("skins")
@ -38,7 +42,7 @@ func main() {
apiRouter := router.PathPrefix("/api").Subrouter()
apiRouter.HandleFunc("/user/{username}/skin", routes.SetSkin).Methods("POST")
services.RedisPool = pool
services.RedisPool = redisPool
services.Router = router
/*go func() {