From ec18775e26947443bcec7bc9095cab877f79382f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sat, 24 Apr 2021 21:37:43 +0200 Subject: [PATCH] change error messages punctuation. --- internal/api/members/controler.go | 4 ++-- internal/api/room/broadcast.go | 6 +++--- internal/api/room/clipboard.go | 6 +++--- internal/api/room/control.go | 8 ++++---- internal/api/room/handler.go | 2 +- internal/api/room/keyboard.go | 4 ++-- internal/api/room/screen.go | 4 ++-- internal/api/room/upload.go | 20 ++++++++++---------- internal/desktop/xorg/xorg.go | 2 +- internal/http/auth/auth.go | 10 +++++----- internal/member/dummy/provider.go | 4 ++-- internal/member/file/provider.go | 12 ++++++------ internal/member/object/provider.go | 14 +++++++------- internal/session/manager.go | 8 ++++---- internal/utils/http.go | 14 +++++++------- 15 files changed, 59 insertions(+), 59 deletions(-) diff --git a/internal/api/members/controler.go b/internal/api/members/controler.go index 76c01694..a6a44a94 100644 --- a/internal/api/members/controler.go +++ b/internal/api/members/controler.go @@ -71,12 +71,12 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) { } if data.Username == "" { - utils.HttpBadRequest(w, "Username cannot be empty.") + utils.HttpBadRequest(w, "username cannot be empty") return } if data.Password == "" { - utils.HttpBadRequest(w, "Password cannot be empty.") + utils.HttpBadRequest(w, "password cannot be empty") return } diff --git a/internal/api/room/broadcast.go b/internal/api/room/broadcast.go index b3722f53..d7665663 100644 --- a/internal/api/room/broadcast.go +++ b/internal/api/room/broadcast.go @@ -28,13 +28,13 @@ func (h *RoomHandler) boradcastStart(w http.ResponseWriter, r *http.Request) { } if data.URL == "" { - utils.HttpBadRequest(w, "Missing broadcast URL.") + utils.HttpBadRequest(w, "missing broadcast URL") return } broadcast := h.capture.Broadcast() if broadcast.Started() { - utils.HttpUnprocessableEntity(w, "Server is already broadcasting.") + utils.HttpUnprocessableEntity(w, "server is already broadcasting") return } @@ -56,7 +56,7 @@ func (h *RoomHandler) boradcastStart(w http.ResponseWriter, r *http.Request) { func (h *RoomHandler) boradcastStop(w http.ResponseWriter, r *http.Request) { broadcast := h.capture.Broadcast() if !broadcast.Started() { - utils.HttpUnprocessableEntity(w, "Server is not broadcasting.") + utils.HttpUnprocessableEntity(w, "server is not broadcasting") return } diff --git a/internal/api/room/clipboard.go b/internal/api/room/clipboard.go index a241c15f..4a70da3d 100644 --- a/internal/api/room/clipboard.go +++ b/internal/api/room/clipboard.go @@ -64,7 +64,7 @@ func (h *RoomHandler) clipboardGetImage(w http.ResponseWriter, r *http.Request) func (h *RoomHandler) clipboardSetImage(w http.ResponseWriter, r *http.Request) { err := r.ParseMultipartForm(MAX_UPLOAD_SIZE) if err != nil { - utils.HttpBadRequest(w, "Failed to parse multipart form.") + utils.HttpBadRequest(w, "failed to parse multipart form") return } @@ -73,7 +73,7 @@ func (h *RoomHandler) clipboardSetImage(w http.ResponseWriter, r *http.Request) file, header, err := r.FormFile("file") if err != nil { - utils.HttpBadRequest(w, "No file received.") + utils.HttpBadRequest(w, "no file received") return } @@ -81,7 +81,7 @@ func (h *RoomHandler) clipboardSetImage(w http.ResponseWriter, r *http.Request) mime := header.Header.Get("Content-Type") if !strings.HasPrefix(mime, "image/") { - utils.HttpBadRequest(w, "File must be image.") + utils.HttpBadRequest(w, "file must be image") return } diff --git a/internal/api/room/control.go b/internal/api/room/control.go index b58a3b70..0bd5518a 100644 --- a/internal/api/room/control.go +++ b/internal/api/room/control.go @@ -36,7 +36,7 @@ func (h *RoomHandler) controlStatus(w http.ResponseWriter, r *http.Request) { func (h *RoomHandler) controlRequest(w http.ResponseWriter, r *http.Request) { host := h.sessions.GetHost() if host != nil { - utils.HttpUnprocessableEntity(w, "There is already a host.") + utils.HttpUnprocessableEntity(w, "there is already a host") return } @@ -49,7 +49,7 @@ func (h *RoomHandler) controlRequest(w http.ResponseWriter, r *http.Request) { func (h *RoomHandler) controlRelease(w http.ResponseWriter, r *http.Request) { session := auth.GetSession(r) if !session.IsHost() { - utils.HttpUnprocessableEntity(w, "Session is not the host.") + utils.HttpUnprocessableEntity(w, "session is not the host") return } @@ -71,12 +71,12 @@ func (h *RoomHandler) controlGive(w http.ResponseWriter, r *http.Request) { target, ok := h.sessions.Get(sessionId) if !ok { - utils.HttpNotFound(w, "Target session was not found.") + utils.HttpNotFound(w, "target session was not found") return } if !target.Profile().CanHost { - utils.HttpBadRequest(w, "Target session is not allowed to host.") + utils.HttpBadRequest(w, "target session is not allowed to host") return } diff --git a/internal/api/room/handler.go b/internal/api/room/handler.go index 4f14e751..dc1e88d9 100644 --- a/internal/api/room/handler.go +++ b/internal/api/room/handler.go @@ -90,7 +90,7 @@ func (h *RoomHandler) uploadMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := auth.GetSession(r) if !session.IsHost() && (!session.Profile().CanHost || !h.sessions.ImplicitHosting()) { - utils.HttpForbidden(w, "Without implicit hosting, only host can upload files.") + utils.HttpForbidden(w, "without implicit hosting, only host can upload files") } else { next.ServeHTTP(w, r) } diff --git a/internal/api/room/keyboard.go b/internal/api/room/keyboard.go index 88d1fb58..dd1b4c72 100644 --- a/internal/api/room/keyboard.go +++ b/internal/api/room/keyboard.go @@ -29,7 +29,7 @@ func (h *RoomHandler) keyboardMapSet(w http.ResponseWriter, r *http.Request) { }) if err != nil { - utils.HttpInternalServerError(w, "Unable to change keyboard map.") + utils.HttpInternalServerError(w, "unable to change keyboard map") return } @@ -40,7 +40,7 @@ func (h *RoomHandler) keyboardMapGet(w http.ResponseWriter, r *http.Request) { data, err := h.desktop.GetKeyboardMap() if err != nil { - utils.HttpInternalServerError(w, "Unable to get keyboard map.") + utils.HttpInternalServerError(w, "unable to get keyboard map") return } diff --git a/internal/api/room/screen.go b/internal/api/room/screen.go index f94f66b3..ba70fa1b 100644 --- a/internal/api/room/screen.go +++ b/internal/api/room/screen.go @@ -20,7 +20,7 @@ func (h *RoomHandler) screenConfiguration(w http.ResponseWriter, r *http.Request size := h.desktop.GetScreenSize() if size == nil { - utils.HttpInternalServerError(w, "Unable to get screen configuration.") + utils.HttpInternalServerError(w, "unable to get screen configuration") return } @@ -96,7 +96,7 @@ func (h *RoomHandler) screenShotGet(w http.ResponseWriter, r *http.Request) { func (h *RoomHandler) screenCastGet(w http.ResponseWriter, r *http.Request) { screencast := h.capture.Screencast() if !screencast.Enabled() { - utils.HttpBadRequest(w, "Screencast pipeline is not enabled.") + utils.HttpBadRequest(w, "screencast pipeline is not enabled") return } diff --git a/internal/api/room/upload.go b/internal/api/room/upload.go index 52b224ac..86dbac8f 100644 --- a/internal/api/room/upload.go +++ b/internal/api/room/upload.go @@ -19,7 +19,7 @@ const ( func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) { err := r.ParseMultipartForm(MAX_UPLOAD_SIZE) if err != nil { - utils.HttpBadRequest(w, "Failed to parse multipart form.") + utils.HttpBadRequest(w, "failed to parse multipart form") return } @@ -28,19 +28,19 @@ func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) { X, err := strconv.Atoi(r.FormValue("x")) if err != nil { - utils.HttpBadRequest(w, "No X coordinate received.") + utils.HttpBadRequest(w, "no X coordinate received") return } Y, err := strconv.Atoi(r.FormValue("y")) if err != nil { - utils.HttpBadRequest(w, "No Y coordinate received.") + utils.HttpBadRequest(w, "no Y coordinate received") return } req_files := r.MultipartForm.File["files"] if len(req_files) == 0 { - utils.HttpBadRequest(w, "No files received.") + utils.HttpBadRequest(w, "no files received") return } @@ -80,7 +80,7 @@ func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) { } if !h.desktop.DropFiles(X, Y, files) { - utils.HttpInternalServerError(w, "Unable to drop files.") + utils.HttpInternalServerError(w, "unable to drop files") return } @@ -90,7 +90,7 @@ func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) { func (h *RoomHandler) uploadDialogPost(w http.ResponseWriter, r *http.Request) { err := r.ParseMultipartForm(MAX_UPLOAD_SIZE) if err != nil { - utils.HttpBadRequest(w, "Failed to parse multipart form.") + utils.HttpBadRequest(w, "failed to parse multipart form") return } @@ -98,13 +98,13 @@ func (h *RoomHandler) uploadDialogPost(w http.ResponseWriter, r *http.Request) { defer r.MultipartForm.RemoveAll() if !h.desktop.IsFileChooserDialogOpened() { - utils.HttpBadRequest(w, "Open file chooser dialog first.") + utils.HttpBadRequest(w, "open file chooser dialog first") return } req_files := r.MultipartForm.File["files"] if len(req_files) == 0 { - utils.HttpBadRequest(w, "No files received.") + utils.HttpBadRequest(w, "no files received") return } @@ -141,7 +141,7 @@ func (h *RoomHandler) uploadDialogPost(w http.ResponseWriter, r *http.Request) { } if err := h.desktop.HandleFileChooserDialog(dir); err != nil { - utils.HttpInternalServerError(w, "Unable to handle file chooser dialog.") + utils.HttpInternalServerError(w, "unable to handle file chooser dialog") return } @@ -150,7 +150,7 @@ func (h *RoomHandler) uploadDialogPost(w http.ResponseWriter, r *http.Request) { func (h *RoomHandler) uploadDialogClose(w http.ResponseWriter, r *http.Request) { if !h.desktop.IsFileChooserDialogOpened() { - utils.HttpBadRequest(w, "File chooser dialog is not open.") + utils.HttpBadRequest(w, "file chooser dialog is not open") return } diff --git a/internal/desktop/xorg/xorg.go b/internal/desktop/xorg/xorg.go index 357b7474..e605fd5b 100644 --- a/internal/desktop/xorg/xorg.go +++ b/internal/desktop/xorg/xorg.go @@ -192,7 +192,7 @@ func ChangeScreenSize(width int, height int, rate int16) error { } } - return fmt.Errorf("Unknown screen configuration %dx%d@%d.", width, height, rate) + return fmt.Errorf("unknown screen configuration %dx%d@%d", width, height, rate) } func GetScreenSize() *types.ScreenSize { diff --git a/internal/http/auth/auth.go b/internal/http/auth/auth.go index 22dbc475..eed1d303 100644 --- a/internal/http/auth/auth.go +++ b/internal/http/auth/auth.go @@ -27,7 +27,7 @@ func AdminsOnly(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := GetSession(r) if !session.Profile().IsAdmin { - utils.HttpForbidden(w, "Only admin can do this.") + utils.HttpForbidden(w) } else { next.ServeHTTP(w, r) } @@ -38,7 +38,7 @@ func HostsOnly(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := GetSession(r) if !session.IsHost() { - utils.HttpForbidden(w, "Only host can do this.") + utils.HttpForbidden(w, "only host can do this") } else { next.ServeHTTP(w, r) } @@ -49,7 +49,7 @@ func CanWatchOnly(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := GetSession(r) if !session.Profile().CanWatch { - utils.HttpForbidden(w, "Only sessions, that can watch.") + utils.HttpForbidden(w) } else { next.ServeHTTP(w, r) } @@ -60,7 +60,7 @@ func CanHostOnly(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := GetSession(r) if !session.Profile().CanHost { - utils.HttpForbidden(w, "Only sessions, that can host.") + utils.HttpForbidden(w) } else { next.ServeHTTP(w, r) } @@ -71,7 +71,7 @@ func CanAccessClipboardOnly(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := GetSession(r) if !session.Profile().CanAccessClipboard { - utils.HttpForbidden(w, "Only sessions, that can access clipboard.") + utils.HttpForbidden(w) } else { next.ServeHTTP(w, r) } diff --git a/internal/member/dummy/provider.go b/internal/member/dummy/provider.go index abd7b4f5..8072e79b 100644 --- a/internal/member/dummy/provider.go +++ b/internal/member/dummy/provider.go @@ -37,7 +37,7 @@ func (provider *MemberProviderCtx) Authenticate(username string, password string } func (provider *MemberProviderCtx) Insert(username string, password string, profile types.MemberProfile) (string, error) { - return "", fmt.Errorf("Not implemented.") + return "", fmt.Errorf("not implemented") } func (provider *MemberProviderCtx) Select(id string) (types.MemberProfile, error) { @@ -54,7 +54,7 @@ func (provider *MemberProviderCtx) UpdateProfile(id string, profile types.Member } func (provider *MemberProviderCtx) UpdatePassword(id string, password string) error { - return fmt.Errorf("Not implemented.") + return fmt.Errorf("not implemented") } func (provider *MemberProviderCtx) Delete(id string) error { diff --git a/internal/member/file/provider.go b/internal/member/file/provider.go index 4a9db72d..e3ec3476 100644 --- a/internal/member/file/provider.go +++ b/internal/member/file/provider.go @@ -38,7 +38,7 @@ func (provider *MemberProviderCtx) Authenticate(username string, password string // TODO: Use hash function. if entry.Password != password { - return "", types.MemberProfile{}, fmt.Errorf("Invalid password.") + return "", types.MemberProfile{}, fmt.Errorf("invalid password") } return id, entry.Profile, nil @@ -55,7 +55,7 @@ func (provider *MemberProviderCtx) Insert(username string, password string, prof _, ok := entries[id] if ok { - return "", fmt.Errorf("Member ID already exists.") + return "", fmt.Errorf("member ID already exists") } entries[id] = MemberEntry{ @@ -75,7 +75,7 @@ func (provider *MemberProviderCtx) UpdateProfile(id string, profile types.Member entry, ok := entries[id] if !ok { - return fmt.Errorf("Member ID does not exist.") + return fmt.Errorf("member ID does not exist") } entry.Profile = profile @@ -92,7 +92,7 @@ func (provider *MemberProviderCtx) UpdatePassword(id string, password string) er entry, ok := entries[id] if !ok { - return fmt.Errorf("Member ID does not exist.") + return fmt.Errorf("member ID does not exist") } // TODO: Use hash function. @@ -139,7 +139,7 @@ func (provider *MemberProviderCtx) Delete(id string) error { _, ok := entries[id] if !ok { - return fmt.Errorf("Member ID does not exist.") + return fmt.Errorf("member ID does not exist") } delete(entries, id) @@ -178,7 +178,7 @@ func (provider *MemberProviderCtx) getEntry(id string) (MemberEntry, error) { entry, ok := entries[id] if !ok { - return MemberEntry{}, fmt.Errorf("Member ID does not exist.") + return MemberEntry{}, fmt.Errorf("member ID does not exist") } return entry, nil diff --git a/internal/member/object/provider.go b/internal/member/object/provider.go index 8a194b2c..68855d65 100644 --- a/internal/member/object/provider.go +++ b/internal/member/object/provider.go @@ -60,12 +60,12 @@ func (provider *MemberProviderCtx) Authenticate(username string, password string entry, ok := provider.entries[id] if !ok { - return "", types.MemberProfile{}, fmt.Errorf("Member ID does not exist.") + return "", types.MemberProfile{}, fmt.Errorf("member ID does not exist") } // TODO: Use hash function. if entry.Password != password { - return "", types.MemberProfile{}, fmt.Errorf("Invalid password.") + return "", types.MemberProfile{}, fmt.Errorf("invalid password") } return id, entry.Profile, nil @@ -77,7 +77,7 @@ func (provider *MemberProviderCtx) Insert(username string, password string, prof _, ok := provider.entries[id] if ok { - return "", fmt.Errorf("Member ID already exists.") + return "", fmt.Errorf("member ID already exists") } provider.entries[id] = &MemberEntry{ @@ -92,7 +92,7 @@ func (provider *MemberProviderCtx) Insert(username string, password string, prof func (provider *MemberProviderCtx) UpdateProfile(id string, profile types.MemberProfile) error { entry, ok := provider.entries[id] if !ok { - return fmt.Errorf("Member ID does not exist.") + return fmt.Errorf("member ID does not exist") } entry.Profile = profile @@ -103,7 +103,7 @@ func (provider *MemberProviderCtx) UpdateProfile(id string, profile types.Member func (provider *MemberProviderCtx) UpdatePassword(id string, password string) error { entry, ok := provider.entries[id] if !ok { - return fmt.Errorf("Member ID does not exist.") + return fmt.Errorf("member ID does not exist") } // TODO: Use hash function. @@ -115,7 +115,7 @@ func (provider *MemberProviderCtx) UpdatePassword(id string, password string) er func (provider *MemberProviderCtx) Select(id string) (types.MemberProfile, error) { entry, ok := provider.entries[id] if !ok { - return types.MemberProfile{}, fmt.Errorf("Member ID does not exist.") + return types.MemberProfile{}, fmt.Errorf("member ID does not exist") } return entry.Profile, nil @@ -139,7 +139,7 @@ func (provider *MemberProviderCtx) SelectAll(limit int, offset int) (map[string] func (provider *MemberProviderCtx) Delete(id string) error { _, ok := provider.entries[id] if !ok { - return fmt.Errorf("Member ID does not exist.") + return fmt.Errorf("member ID does not exist") } delete(provider.entries, id) diff --git a/internal/session/manager.go b/internal/session/manager.go index c632b131..50173467 100644 --- a/internal/session/manager.go +++ b/internal/session/manager.go @@ -68,12 +68,12 @@ func (manager *SessionManagerCtx) Create(id string, profile types.MemberProfile) manager.sessionsMu.Lock() if _, ok := manager.sessions[id]; ok { manager.sessionsMu.Unlock() - return nil, "", fmt.Errorf("Session id already exists.") + return nil, "", fmt.Errorf("session id already exists") } if _, ok := manager.tokens[token]; ok { manager.sessionsMu.Unlock() - return nil, "", fmt.Errorf("Session token already exists.") + return nil, "", fmt.Errorf("session token already exists") } session := &SessionCtx{ @@ -98,7 +98,7 @@ func (manager *SessionManagerCtx) Update(id string, profile types.MemberProfile) session, ok := manager.sessions[id] if !ok { manager.sessionsMu.Unlock() - return fmt.Errorf("Session id not found.") + return fmt.Errorf("session id not found") } session.profile = profile @@ -114,7 +114,7 @@ func (manager *SessionManagerCtx) Delete(id string) error { session, ok := manager.sessions[id] if !ok { manager.sessionsMu.Unlock() - return fmt.Errorf("Session id not found.") + return fmt.Errorf("session id not found") } delete(manager.tokens, session.token) diff --git a/internal/utils/http.go b/internal/utils/http.go index f85008f4..124c15fe 100644 --- a/internal/utils/http.go +++ b/internal/utils/http.go @@ -16,7 +16,7 @@ type ErrResponse struct { func HttpJsonRequest(w http.ResponseWriter, r *http.Request, res interface{}) bool { if err := json.NewDecoder(r.Body).Decode(res); err != nil { if err == io.EOF { - HttpBadRequest(w, "No data provided.") + HttpBadRequest(w, "no data provided") } else { HttpBadRequest(w, err) } @@ -53,27 +53,27 @@ func HttpSuccess(w http.ResponseWriter, res ...interface{}) { } func HttpBadRequest(w http.ResponseWriter, res ...interface{}) { - defHttpError(w, http.StatusBadRequest, "Bad Request.", res...) + defHttpError(w, http.StatusBadRequest, "bad request", res...) } func HttpUnauthorized(w http.ResponseWriter, res ...interface{}) { - defHttpError(w, http.StatusUnauthorized, "Invalid or missing access token.", res...) + defHttpError(w, http.StatusUnauthorized, "invalid or missing access token", res...) } func HttpForbidden(w http.ResponseWriter, res ...interface{}) { - defHttpError(w, http.StatusForbidden, "Access token does not have the required scope.", res...) + defHttpError(w, http.StatusForbidden, "access token does not have the required scope", res...) } func HttpNotFound(w http.ResponseWriter, res ...interface{}) { - defHttpError(w, http.StatusNotFound, "Resource not found.", res...) + defHttpError(w, http.StatusNotFound, "resource not found", res...) } func HttpUnprocessableEntity(w http.ResponseWriter, res ...interface{}) { - defHttpError(w, http.StatusUnprocessableEntity, "Unprocessable Entity.", res...) + defHttpError(w, http.StatusUnprocessableEntity, "unprocessable entity", res...) } func HttpInternalServerError(w http.ResponseWriter, res ...interface{}) { - defHttpError(w, http.StatusInternalServerError, "Internal server error.", res...) + defHttpError(w, http.StatusInternalServerError, "internal server error", res...) } func defHttpError(w http.ResponseWriter, status int, text string, res ...interface{}) {