From 1042838b5264f0f9f31304f9f70dd6365982f8d4 Mon Sep 17 00:00:00 2001 From: nronzel <86695181+nronzel@users.noreply.github.com> Date: Sun, 11 Feb 2024 10:53:12 -0500 Subject: [PATCH 1/7] updated README --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9871a5b..e667165 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,7 @@ This project is dockerized and gets deployed to Google Cloud Run. - [x] Rate limiting - [ ] Better HTMX errors - [ ] More tests -- [ ] Semver versioning +- [x] Semver versioning ## Features From 694844ad7f5bc0be462190ac3e43e4ac2b86aca2 Mon Sep 17 00:00:00 2001 From: nronzel <86695181+nronzel@users.noreply.github.com> Date: Sun, 11 Feb 2024 11:22:57 -0500 Subject: [PATCH 2/7] feat: replaced Chi with default Go 1.22 servemux no need for the dependency for such a lightweight API. The default servemux will be perfectly fine. --- main.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) 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, From b5c6c01e82dbbe026c0f7e7fc02a0b2c14a3b265 Mon Sep 17 00:00:00 2001 From: nronzel <86695181+nronzel@users.noreply.github.com> Date: Sun, 11 Feb 2024 11:24:20 -0500 Subject: [PATCH 3/7] updated README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e667165..6b8470b 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ This project is dockerized and gets deployed to Google Cloud Run. - [x] Rate limiting - [ ] Better HTMX errors - [ ] More tests +- [x] Use the new ServeMux in Go 1.22 to replace Chi - [x] Semver versioning ## Features From 8a9175b8b76bf6d27c73c02056ae1ca7b2679c85 Mon Sep 17 00:00:00 2001 From: nronzel <86695181+nronzel@users.noreply.github.com> Date: Sun, 11 Feb 2024 11:51:56 -0500 Subject: [PATCH 4/7] updated README --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 6b8470b..50a8bef 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,6 @@ cd xoracle 3. Install dependencies: -- Chi v5 - golang.org/x/time Install dependencies with the command: From c6fb8a7bcb7de5db218b5bf386cc4b7b2b50c25b Mon Sep 17 00:00:00 2001 From: nronzel <86695181+nronzel@users.noreply.github.com> Date: Sun, 11 Feb 2024 11:52:09 -0500 Subject: [PATCH 5/7] chore: added log statement --- pkg/rate_limiter/limit.go | 1 + 1 file changed, 1 insertion(+) 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 } From 6a6cf71154047776878723ad2bc61a25a4ae0245 Mon Sep 17 00:00:00 2001 From: nronzel <86695181+nronzel@users.noreply.github.com> Date: Sun, 11 Feb 2024 11:52:20 -0500 Subject: [PATCH 6/7] chore: formatting --- pkg/decryption/decryption.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 { From 8d4c52521441da35414614611be732ba8e856d52 Mon Sep 17 00:00:00 2001 From: nronzel <86695181+nronzel@users.noreply.github.com> Date: Sun, 11 Feb 2024 11:53:23 -0500 Subject: [PATCH 7/7] add .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7056f80 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +xoracle