diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7056f80 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +xoracle diff --git a/README.md b/README.md index 9871a5b..50a8bef 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ ![cd-status](https://img.shields.io/github/actions/workflow/status/nronzel/xoracle/cd.yml?label=cd) ![top-lang](https://img.shields.io/github/languages/top/nronzel/xoracle?logo=go) ![docker-pulls](https://img.shields.io/docker/pulls/sutats/xoracle?logo=docker) -![licent](https://img.shields.io/github/license/nronzel/xoracle) +![license](https://img.shields.io/github/license/nronzel/xoracle) +![tag](https://img.shields.io/github/v/tag/nronzel/xoracle) # XORacle @@ -20,7 +21,8 @@ This project is dockerized and gets deployed to Google Cloud Run. - [x] Rate limiting - [ ] Better HTMX errors - [ ] More tests -- [ ] Semver versioning +- [x] Use the new ServeMux in Go 1.22 to replace Chi +- [x] Semver versioning ## Features @@ -104,7 +106,6 @@ cd xoracle 3. Install dependencies: -- Chi v5 - golang.org/x/time Install dependencies with the command: diff --git a/main.go b/main.go index 86b906d..081fabb 100644 --- a/main.go +++ b/main.go @@ -8,22 +8,19 @@ import ( "github.com/nronzel/xoracle/pkg/handlers" limiter "github.com/nronzel/xoracle/pkg/rate_limiter" - - "github.com/go-chi/chi/v5" ) func main() { - r := chi.NewRouter() - - r.Get("/", handlers.HandlerRoot) + mux := http.NewServeMux() - r.Post("/decrypt", handlers.HandlerDecrypt) + mux.HandleFunc("GET /", handlers.HandlerRoot) + mux.HandleFunc("POST /decrypt", handlers.HandlerDecrypt) rl := limiter.NewRateLimiter(1, 3) server := &http.Server{ Addr: ":8080", - Handler: rl.Limit(r), + Handler: rl.Limit(mux), ReadTimeout: 5 * time.Second, WriteTimeout: 10 * time.Second, IdleTimeout: 15 * time.Second, diff --git a/pkg/decryption/decryption.go b/pkg/decryption/decryption.go index 920c09b..0477097 100644 --- a/pkg/decryption/decryption.go +++ b/pkg/decryption/decryption.go @@ -97,7 +97,7 @@ type DecryptionResult struct { DecryptedData string } -// processKeySizes attempts to decrypt the provided byte slice (data) for each +// ProcessKeySizes attempts to decrypt the provided byte slice (data) for each // of the top key sizes found. It attempts to break a repeating-key XOR cipher // without directly knowing the key. func ProcessKeySizes(topKeySizes []int, data []byte) []DecryptionResult { diff --git a/pkg/rate_limiter/limit.go b/pkg/rate_limiter/limit.go index 70b9017..54a686a 100644 --- a/pkg/rate_limiter/limit.go +++ b/pkg/rate_limiter/limit.go @@ -97,6 +97,7 @@ func (rl *RateLimiter) Limit(next http.Handler) http.Handler { // Call getVisitor func to retrive the rate limiter for the current user limiter := rl.getVisitor(ip) if !limiter.Allow() { + log.Printf("%s has been rate limited", ip) http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests) return }