mirror of
https://github.com/elyby/chrly.git
synced 2024-11-17 18:52:58 +05:30
Добавлен обработчик NotFound
Исправлена опечатка в тесте Разделена логика метода BuildNonElyTexturesHash
This commit is contained in:
parent
c4cd95cddc
commit
3d65529d2e
18
lib/routes/NotFound.go
Normal file
18
lib/routes/NotFound.go
Normal file
@ -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)
|
||||
}
|
@ -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()
|
||||
}
|
||||
|
@ -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:")
|
||||
}
|
||||
}
|
||||
|
@ -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: убрать этого, т.к. он стар
|
||||
|
Loading…
Reference in New Issue
Block a user