Refactor server package structure and update error handling methods; remove unused dependencies

This commit is contained in:
alex
2025-06-22 11:54:16 +03:00
parent eaff815270
commit 0d8673254e
9 changed files with 32 additions and 21 deletions

View File

@@ -1,12 +1,3 @@
module github.com/akyaiy/GoSally-mvp/internal/logs
go 1.24.4
require github.com/ilyakaznacheev/cleanenv v1.5.0
require (
github.com/BurntSushi/toml v1.5.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect
)

View File

@@ -1,4 +1,4 @@
module github.com/akyaiy/GoSally-mvp/internal/server_v1
module github.com/akyaiy/GoSally-mvp/internal/server/v1
go 1.24.4

View File

@@ -1,4 +1,4 @@
package server_v1
package v1
import (
"encoding/json"

View File

@@ -1,4 +1,4 @@
package server_v1
package v1
import (
"encoding/json"

View File

@@ -1,4 +1,4 @@
package server_v1
package v1
import (
"log/slog"
@@ -12,7 +12,9 @@ type ServerV1UtilsContract interface {
extractDescriptionStatic(path string) (string, error)
writeJSONError(status int, msg string)
newUUID() string
errNotFound()
_errNotFound()
ErrNotFound(w http.ResponseWriter, r *http.Request)
}
type ServerV1Contract interface {
@@ -37,6 +39,10 @@ type HandlerV1 struct {
listAllowedCmd *regexp.Regexp
}
func InitV1Server(o *HandlerV1) *HandlerV1 {
return o
}
func (h *HandlerV1) Handle(w http.ResponseWriter, r *http.Request) {
h.w = w
h.r = r

View File

@@ -1,4 +1,4 @@
package server_v1
package v1
import (
"crypto/rand"
@@ -10,6 +10,12 @@ import (
"regexp"
)
func (h *HandlerV1) ErrNotFound(w http.ResponseWriter, r *http.Request) {
h.w = w
h.r = r
h._errNotFound()
}
func (h *HandlerV1) newUUID() string {
bytes := make([]byte, 16)
_, err := rand.Read(bytes)
@@ -20,7 +26,7 @@ func (h *HandlerV1) newUUID() string {
return hex.EncodeToString(bytes)
}
func (h *HandlerV1) errNotFound() {
func (h *HandlerV1) _errNotFound() {
h.writeJSONError(http.StatusBadRequest, "invalid request")
h.log.Error("HTTP request error", slog.String("remote", h.r.RemoteAddr), slog.String("method", h.r.Method), slog.String("url", h.r.URL.String()), slog.Int("status", http.StatusBadRequest))
}