mirror of
https://github.com/elyby/chrly.git
synced 2024-12-22 21:19:55 +05:30
Merge branch 'develop'
This commit is contained in:
commit
45007ba1c5
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
# IDEA
|
||||
/.idea
|
||||
|
||||
# Docker Compose override file
|
||||
# Docker Compose file
|
||||
docker-compose.yml
|
||||
docker-compose.override.yml
|
||||
|
27
README.md
27
README.md
@ -15,30 +15,19 @@ ln -s $PWD $GOPATH/src/elyby/minecraft-skinsystem
|
||||
git clone git@bitbucket.org:elyby/minecraft-skinsystem.git $GOPATH/src/elyby/minecraft-skinsystem
|
||||
```
|
||||
|
||||
Поднять репозиторий можно командой:
|
||||
Нужно скопировать правильный docker-compose файл для желаемого окружения:
|
||||
|
||||
```sh
|
||||
cp docker-compose.dev.yml docker-compose.yml # dev env
|
||||
cp docker-compose.prod.yml docker-compose.yml # prod env
|
||||
```
|
||||
|
||||
И за тем всё это поднять:
|
||||
|
||||
```sh
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
Рекомендуемый файл `docker-compose.override.yml` для dev-окружения:
|
||||
|
||||
```sh
|
||||
version: '2'
|
||||
services:
|
||||
app:
|
||||
volumes:
|
||||
- ./:/go/src/app
|
||||
command: ["go", "run", "minecraft-skinsystem.go"]
|
||||
```
|
||||
|
||||
В таком случае, для перезапуска контейнера (при условии, что не появляется
|
||||
новых зависимостей) будет достаточно выполнить только одну команду:
|
||||
|
||||
```sh
|
||||
docker-compose restart app
|
||||
```
|
||||
|
||||
Если нужно пересобрать весь контейнер, то выполняем следующее:
|
||||
|
||||
```
|
||||
|
0
data/.gitignore → data/redis/.gitignore
vendored
0
data/.gitignore → data/redis/.gitignore
vendored
@ -1,13 +1,10 @@
|
||||
version: '2'
|
||||
services:
|
||||
app:
|
||||
build: .
|
||||
links:
|
||||
- redis
|
||||
ports:
|
||||
- "80:80"
|
||||
|
||||
redis:
|
||||
image: redis:3.0
|
||||
volumes:
|
||||
- ./data/:/data
|
||||
- ./data/redis:/data
|
17
docker-compose.dev.yml
Normal file
17
docker-compose.dev.yml
Normal file
@ -0,0 +1,17 @@
|
||||
version: '2'
|
||||
services:
|
||||
app:
|
||||
extends:
|
||||
file: docker-compose.base.yml
|
||||
service: app
|
||||
build: .
|
||||
volumes:
|
||||
- ./:/go/src/app
|
||||
command: ["go", "run", "minecraft-skinsystem.go"]
|
||||
links:
|
||||
- redis
|
||||
|
||||
redis:
|
||||
extends:
|
||||
file: docker-compose.base.yml
|
||||
service: redis
|
16
docker-compose.prod.yml
Normal file
16
docker-compose.prod.yml
Normal file
@ -0,0 +1,16 @@
|
||||
version: '2'
|
||||
services:
|
||||
app:
|
||||
extends:
|
||||
file: docker-compose.base.yml
|
||||
service: app
|
||||
image: erickskrauch/ely-by-skinsystem:master
|
||||
links:
|
||||
- redis
|
||||
restart: always
|
||||
|
||||
redis:
|
||||
extends:
|
||||
file: docker-compose.base.yml
|
||||
service: redis
|
||||
restart: always
|
11
lib/data/DataNotFound.go
Normal file
11
lib/data/DataNotFound.go
Normal file
@ -0,0 +1,11 @@
|
||||
package data
|
||||
|
||||
import "fmt"
|
||||
|
||||
type DataNotFound struct {
|
||||
Who string
|
||||
}
|
||||
|
||||
func (e DataNotFound) Error() string {
|
||||
return fmt.Sprintf("Skin data not found. Required username \"%v\"", e.Who)
|
||||
}
|
@ -6,6 +6,8 @@ import (
|
||||
|
||||
"elyby/minecraft-skinsystem/lib/services"
|
||||
"elyby/minecraft-skinsystem/lib/tools"
|
||||
|
||||
"github.com/mediocregopher/radix.v2/redis"
|
||||
)
|
||||
|
||||
type SkinItem struct {
|
||||
@ -25,14 +27,17 @@ func (s *SkinItem) Save() {
|
||||
|
||||
func FindRecord(username string) (SkinItem, error) {
|
||||
var record SkinItem;
|
||||
result, err := services.RedisPool.Cmd("GET", tools.BuildKey(username)).Str();
|
||||
response := services.RedisPool.Cmd("GET", tools.BuildKey(username));
|
||||
if (response.IsType(redis.Nil)) {
|
||||
return record, DataNotFound{username}
|
||||
}
|
||||
|
||||
result, err := response.Str()
|
||||
if (err == nil) {
|
||||
decodeErr := json.Unmarshal([]byte(result), &record)
|
||||
if (decodeErr != nil) {
|
||||
log.Println("Cannot decode record data")
|
||||
}
|
||||
} else {
|
||||
log.Println("Error on request user data: " + err.Error())
|
||||
}
|
||||
|
||||
return record, err
|
||||
|
@ -1,6 +1,7 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
@ -10,6 +11,7 @@ import (
|
||||
|
||||
func Cape(w http.ResponseWriter, r *http.Request) {
|
||||
username := tools.ParseUsername(mux.Vars(r)["username"])
|
||||
log.Println("request cape for username " + username)
|
||||
http.Redirect(w, r, "http://skins.minecraft.net/MinecraftCloaks/" + username + ".png", 301)
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,16 @@ import (
|
||||
const redisString string = "redis:6379"
|
||||
|
||||
func main() {
|
||||
log.Println("Starting...")
|
||||
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
||||
pool, redisErr := pool.New("tcp", redisString, 10)
|
||||
log.Println("Connecting to redis")
|
||||
redisPool, redisErr := pool.New("tcp", redisString, 10)
|
||||
if redisErr != nil {
|
||||
log.Fatal("Redis unavailable")
|
||||
}
|
||||
log.Println("Connected to redis")
|
||||
|
||||
router := mux.NewRouter().StrictSlash(true)
|
||||
router.HandleFunc("/skins/{username}", routes.Skin).Methods("GET").Name("skins")
|
||||
@ -38,7 +42,7 @@ func main() {
|
||||
apiRouter := router.PathPrefix("/api").Subrouter()
|
||||
apiRouter.HandleFunc("/user/{username}/skin", routes.SetSkin).Methods("POST")
|
||||
|
||||
services.RedisPool = pool
|
||||
services.RedisPool = redisPool
|
||||
services.Router = router
|
||||
|
||||
/*go func() {
|
||||
|
Loading…
Reference in New Issue
Block a user