Немного реструктуризации

Добавлен роут для смены скина
This commit is contained in:
ErickSkrauch
2016-07-06 01:25:05 +03:00
parent 87ca1191eb
commit c4cd95cddc
12 changed files with 127 additions and 62 deletions

24
lib/routes/Skin.go Normal file
View File

@@ -0,0 +1,24 @@
package routes
import (
"log"
"net/http"
"github.com/gorilla/mux"
"elyby/minecraft-skinsystem/lib/tools"
"elyby/minecraft-skinsystem/lib/data"
)
func Skin(w http.ResponseWriter, r *http.Request) {
username := tools.ParseUsername(mux.Vars(r)["username"])
log.Println("request skin for username " + username);
rec, err := data.FindRecord(username)
if (err != nil) {
http.Redirect(w, r, "http://skins.minecraft.net/MinecraftSkins/" + username + ".png", 301)
log.Println("Cannot get skin for username " + username)
return
}
http.Redirect(w, r, rec.Url, 301);
}