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 {