diff --git a/cmd/justcaptchad/main.go b/cmd/justcaptchad/main.go index 4b129de..206c373 100644 --- a/cmd/justcaptchad/main.go +++ b/cmd/justcaptchad/main.go @@ -3,8 +3,7 @@ package main import ( "flag" "fmt" - "justcaptcha/internal/handlers" - "justcaptcha/internal/server" + "justcaptcha/internal/http" "log" "net/netip" "os" @@ -29,8 +28,8 @@ func main() { return } - hand := handlers.New(*captchaExpiry) - srv := server.NewHttpServer() + hand := http.NewCaptchaHandlers(*captchaExpiry) + srv := http.NewHttpServer() srv.POST("/", hand.New) srv.POST("/:captcha", hand.Solve) diff --git a/internal/handlers/handlers.go b/internal/http/handlers.go similarity index 86% rename from internal/handlers/handlers.go rename to internal/http/handlers.go index 5ef69b2..b77bf89 100644 --- a/internal/handlers/handlers.go +++ b/internal/http/handlers.go @@ -1,9 +1,8 @@ -package handlers +package http import ( "fmt" "image/jpeg" - "justcaptcha/internal/server" "justcaptcha/pkg/captcha" "justcaptcha/pkg/captcha/inmemdb" "justcaptcha/pkg/dwcaptcha" @@ -18,7 +17,7 @@ type CaptchaHandlers struct { expiry time.Duration } -func New(expiry time.Duration) *CaptchaHandlers { +func NewCaptchaHandlers(expiry time.Duration) *CaptchaHandlers { inmemdb.SetExpiry(expiry) return &CaptchaHandlers{expiry: expiry} } @@ -31,7 +30,7 @@ func (h *CaptchaHandlers) New(w http.ResponseWriter, r *http.Request) { } func (h *CaptchaHandlers) Image(w http.ResponseWriter, r *http.Request) { - captchaID := captcha.ID(server.GetURLParam(r, "captcha")) + captchaID := captcha.ID(GetURLParam(r, "captcha")) captchaStyle := r.URL.Query().Get("style") captchaImage := inmemdb.Image(captchaID, captchaStyle) @@ -46,7 +45,7 @@ func (h *CaptchaHandlers) Image(w http.ResponseWriter, r *http.Request) { } func (h *CaptchaHandlers) Solve(w http.ResponseWriter, r *http.Request) { - captchaID := captcha.ID(server.GetURLParam(r, "captcha")) + captchaID := captcha.ID(GetURLParam(r, "captcha")) r.ParseForm() answer := captcha.Answer(r.FormValue("answer")) @@ -60,7 +59,7 @@ func (h *CaptchaHandlers) Solve(w http.ResponseWriter, r *http.Request) { } func (h *CaptchaHandlers) IsSolved(w http.ResponseWriter, r *http.Request) { - captchaID := captcha.ID(server.GetURLParam(r, "captcha")) + captchaID := captcha.ID(GetURLParam(r, "captcha")) isJustRemove := r.URL.Query().Has("remove") if isJustRemove { diff --git a/internal/server/http.go b/internal/http/server.go similarity index 99% rename from internal/server/http.go rename to internal/http/server.go index 37d59eb..bac4ca8 100644 --- a/internal/server/http.go +++ b/internal/http/server.go @@ -1,4 +1,4 @@ -package server +package http import ( "context"