From 3d65529d2e668b212ea7949dd23c2ee72efdf2de Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 6 Jul 2016 14:45:14 +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=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=87=D0=B8?= =?UTF-8?q?=D0=BA=20NotFound=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=BF=D0=B5=D1=87=D0=B0=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B2=20=D1=82=D0=B5=D1=81=D1=82=D0=B5=20=D0=A0=D0=B0?= =?UTF-8?q?=D0=B7=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=B8=D0=BA=D0=B0=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20Bui?= =?UTF-8?q?ldNonElyTexturesHash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/NotFound.go | 18 ++++++++++++++++++ lib/tools/tools.go | 8 ++++++-- lib/tools/tools_test.go | 2 +- minecraft-skinsystem.go | 1 + 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 lib/routes/NotFound.go diff --git a/lib/routes/NotFound.go b/lib/routes/NotFound.go new file mode 100644 index 0000000..8460956 --- /dev/null +++ b/lib/routes/NotFound.go @@ -0,0 +1,18 @@ +package routes + +import ( + "net/http" + "encoding/json" +) + +func NotFound(w http.ResponseWriter, r *http.Request) { + json, _ := json.Marshal(map[string]string{ + "status": "404", + "message": "Not Found", + "link": "http://docs.ely.by", + }) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusNotFound) + w.Write(json) +} diff --git a/lib/tools/tools.go b/lib/tools/tools.go index 6268c21..0814856 100644 --- a/lib/tools/tools.go +++ b/lib/tools/tools.go @@ -18,8 +18,7 @@ func ParseUsername(username string) string { } func BuildNonElyTexturesHash(username string) string { - n := time.Now() - hour := time.Date(n.Year(), n.Month(), n.Day(), n.Hour(), 0, 0, 0, time.UTC).Unix() + hour := getCurrentHour() hasher := md5.New() hasher.Write([]byte("non-ely-" + strconv.FormatInt(hour, 10) + "-" + username)) @@ -29,3 +28,8 @@ func BuildNonElyTexturesHash(username string) string { func BuildKey(username string) string { return "username:" + strings.ToLower(username) } + +func getCurrentHour() int64 { + n := time.Now() + return time.Date(n.Year(), n.Month(), n.Day(), n.Hour(), 0, 0, 0, time.UTC).Unix() +} diff --git a/lib/tools/tools_test.go b/lib/tools/tools_test.go index 54b49f1..bf7b7f1 100644 --- a/lib/tools/tools_test.go +++ b/lib/tools/tools_test.go @@ -17,6 +17,6 @@ func TestParseUsername(t *testing.T) { func TestBuildKey(t *testing.T) { if BuildKey("Test") != "username:test" { - t.Error("Function shound convert string to lover case and concatenate it with usernmae:") + t.Error("Function shound convert string to lower case and concatenate it with usernmae:") } } diff --git a/minecraft-skinsystem.go b/minecraft-skinsystem.go index 3946b1b..64f03ca 100644 --- a/minecraft-skinsystem.go +++ b/minecraft-skinsystem.go @@ -21,6 +21,7 @@ func main() { services.Redis = client router := mux.NewRouter().StrictSlash(true) + router.HandleFunc("/", routes.NotFound) router.HandleFunc("/skins/{username}", routes.Skin).Methods("GET") router.HandleFunc("/textures/{username}", routes.Textures).Methods("GET") router.HandleFunc("/system/setSkin", routes.SetSkin).Methods("POST") // TODO: убрать этого, т.к. он стар