mirror of
https://github.com/elyby/chrly.git
synced 2025-01-03 18:51:49 +05:30
Удалено логирование ожидаемой ошибки с несуществованием скина в redis.
This commit is contained in:
parent
89ea6e5ee8
commit
4bdab704a5
11
lib/data/DataNotFound.go
Normal file
11
lib/data/DataNotFound.go
Normal 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)
|
||||||
|
}
|
@ -6,6 +6,8 @@ import (
|
|||||||
|
|
||||||
"elyby/minecraft-skinsystem/lib/services"
|
"elyby/minecraft-skinsystem/lib/services"
|
||||||
"elyby/minecraft-skinsystem/lib/tools"
|
"elyby/minecraft-skinsystem/lib/tools"
|
||||||
|
|
||||||
|
"github.com/mediocregopher/radix.v2/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SkinItem struct {
|
type SkinItem struct {
|
||||||
@ -25,14 +27,17 @@ func (s *SkinItem) Save() {
|
|||||||
|
|
||||||
func FindRecord(username string) (SkinItem, error) {
|
func FindRecord(username string) (SkinItem, error) {
|
||||||
var record SkinItem;
|
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) {
|
if (err == nil) {
|
||||||
decodeErr := json.Unmarshal([]byte(result), &record)
|
decodeErr := json.Unmarshal([]byte(result), &record)
|
||||||
if (decodeErr != nil) {
|
if (decodeErr != nil) {
|
||||||
log.Println("Cannot decode record data")
|
log.Println("Cannot decode record data")
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log.Println("Error on request user data: " + err.Error())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return record, err
|
return record, err
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
@ -10,6 +11,7 @@ import (
|
|||||||
|
|
||||||
func Cape(w http.ResponseWriter, r *http.Request) {
|
func Cape(w http.ResponseWriter, r *http.Request) {
|
||||||
username := tools.ParseUsername(mux.Vars(r)["username"])
|
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)
|
http.Redirect(w, r, "http://skins.minecraft.net/MinecraftCloaks/" + username + ".png", 301)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,16 @@ import (
|
|||||||
const redisString string = "redis:6379"
|
const redisString string = "redis:6379"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
log.Println("Starting...")
|
||||||
|
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
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 {
|
if redisErr != nil {
|
||||||
log.Fatal("Redis unavailable")
|
log.Fatal("Redis unavailable")
|
||||||
}
|
}
|
||||||
|
log.Println("Connected to redis")
|
||||||
|
|
||||||
router := mux.NewRouter().StrictSlash(true)
|
router := mux.NewRouter().StrictSlash(true)
|
||||||
router.HandleFunc("/skins/{username}", routes.Skin).Methods("GET").Name("skins")
|
router.HandleFunc("/skins/{username}", routes.Skin).Methods("GET").Name("skins")
|
||||||
@ -38,7 +42,7 @@ func main() {
|
|||||||
apiRouter := router.PathPrefix("/api").Subrouter()
|
apiRouter := router.PathPrefix("/api").Subrouter()
|
||||||
apiRouter.HandleFunc("/user/{username}/skin", routes.SetSkin).Methods("POST")
|
apiRouter.HandleFunc("/user/{username}/skin", routes.SetSkin).Methods("POST")
|
||||||
|
|
||||||
services.RedisPool = pool
|
services.RedisPool = redisPool
|
||||||
services.Router = router
|
services.Router = router
|
||||||
|
|
||||||
/*go func() {
|
/*go func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user