2016-07-05 03:58:09 +05:30
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
2016-07-06 03:55:05 +05:30
|
|
|
"log"
|
2016-07-05 03:58:09 +05:30
|
|
|
"net/http"
|
2016-07-06 03:55:05 +05:30
|
|
|
|
2016-07-05 03:58:09 +05:30
|
|
|
"github.com/gorilla/mux"
|
2016-07-06 03:55:05 +05:30
|
|
|
|
2016-07-05 03:58:09 +05:30
|
|
|
"elyby/minecraft-skinsystem/lib/tools"
|
2016-07-06 03:55:05 +05:30
|
|
|
"elyby/minecraft-skinsystem/lib/data"
|
2016-07-05 03:58:09 +05:30
|
|
|
)
|
|
|
|
|
2016-07-06 03:55:05 +05:30
|
|
|
func Skin(w http.ResponseWriter, r *http.Request) {
|
2016-07-05 03:58:09 +05:30
|
|
|
username := tools.ParseUsername(mux.Vars(r)["username"])
|
|
|
|
log.Println("request skin for username " + username);
|
2016-07-06 03:55:05 +05:30
|
|
|
rec, err := data.FindRecord(username)
|
2016-07-05 03:58:09 +05:30
|
|
|
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);
|
|
|
|
}
|