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: убрать этого, т.к. он стар