From 98b787fa9985e9dad9985224ab0409916dacfd53 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 21 Sep 2016 21:44:52 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=BE=D0=BD=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20?= =?UTF-8?q?=D1=81=D1=83=D1=89=D0=B5=D1=81=D1=82=D0=B2=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D1=81=D0=BA=D0=B8=D0=BD=D0=B0=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=80=D0=BE=D1=83=D1=82=D0=B0=20/cloaks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 2 ++ Dockerfile | 1 + data/capes/.gitignore | 2 ++ lib/routes/Cape.go | 16 +++++++++++++--- lib/services/services.go | 2 ++ minecraft-skinsystem.go | 4 ++++ 6 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 data/capes/.gitignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..dd69578 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +# Игнорим данные, т.к. они не нужны для внутреннего содержимого этого контейнера +data diff --git a/Dockerfile b/Dockerfile index c72d9d7..7e6d16d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/data/capes/.gitignore b/data/capes/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/data/capes/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/lib/routes/Cape.go b/lib/routes/Cape.go index 20020b6..c38b087 100644 --- a/lib/routes/Cape.go +++ b/lib/routes/Cape.go @@ -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) { diff --git a/lib/services/services.go b/lib/services/services.go index 5f4e996..6f7241b 100644 --- a/lib/services/services.go +++ b/lib/services/services.go @@ -8,3 +8,5 @@ import ( var RedisPool *pool.Pool var RabbitMQChannel *amqp.Channel + +var RootFolder string diff --git a/minecraft-skinsystem.go b/minecraft-skinsystem.go index 1f99e2a..3527e36 100644 --- a/minecraft-skinsystem.go +++ b/minecraft-skinsystem.go @@ -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 {