Добавлен функционал проверки существования скина для роута /cloaks

This commit is contained in:
ErickSkrauch 2016-09-21 21:44:52 +03:00
parent 4bcd0495ed
commit 98b787fa99
6 changed files with 24 additions and 3 deletions

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
# Игнорим данные, т.к. они не нужны для внутреннего содержимого этого контейнера
data

View File

@ -1,6 +1,7 @@
FROM golang:1.7
RUN mkdir -p /go/src/elyby/minecraft-skinsystem \
/go/src/elyby/minecraft-skinsystem/data/capes \
&& ln -s /go/src/elyby/minecraft-skinsystem /go/src/app
WORKDIR /go/src/app

2
data/capes/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -1,18 +1,28 @@
package routes
import (
"os"
"io"
"log"
"strings"
"net/http"
"github.com/gorilla/mux"
"elyby/minecraft-skinsystem/lib/tools"
"elyby/minecraft-skinsystem/lib/services"
)
func Cape(w http.ResponseWriter, r *http.Request) {
username := tools.ParseUsername(mux.Vars(r)["username"])
func Cape(response http.ResponseWriter, request *http.Request) {
username := tools.ParseUsername(mux.Vars(request)["username"])
log.Println("request cape for username " + username)
http.Redirect(w, r, "http://skins.minecraft.net/MinecraftCloaks/" + username + ".png", 301)
file, err := os.Open(services.RootFolder + "/data/capes/" + strings.ToLower(username) + ".png")
if (err != nil) {
http.Redirect(response, request, "http://skins.minecraft.net/MinecraftCloaks/" + username + ".png", 301)
}
request.Header.Set("Content-Type", "image/png")
io.Copy(response, file)
}
func CapeGET(w http.ResponseWriter, r *http.Request) {

View File

@ -8,3 +8,5 @@ import (
var RedisPool *pool.Pool
var RabbitMQChannel *amqp.Channel
var RootFolder string

View File

@ -13,6 +13,7 @@ import (
"elyby/minecraft-skinsystem/lib/routes"
"elyby/minecraft-skinsystem/lib/services"
"elyby/minecraft-skinsystem/lib/worker"
"path/filepath"
)
const redisString string = "redis:6379"
@ -64,6 +65,9 @@ func main() {
services.RedisPool = redisPool
services.RabbitMQChannel = rabbitChannel
_, file, _, _ := runtime.Caller(0)
services.RootFolder = filepath.Dir(file)
go func() {
period := 5
for {