From ab74d876c48b44fa238a396d2b70d020d7dc01c2 Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 13:29:07 +0100 Subject: [PATCH 01/19] dodano imie do README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c2bec0368b7..4806d2c22f5 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,5 @@ go build -o notely && ./notely *This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`. You do *not* need to set up a database or any interactivity on the webpage yet. Instructions for that will come later in the course! + +Kacper's version of Boot.dev's Notely app. \ No newline at end of file From 76f9d382ba742c2df52ed2c8fc84701e49f962d0 Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 13:37:49 +0100 Subject: [PATCH 02/19] dodano imie do README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4806d2c22f5..5ed7434c091 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,4 @@ go build -o notely && ./notely You do *not* need to set up a database or any interactivity on the webpage yet. Instructions for that will come later in the course! -Kacper's version of Boot.dev's Notely app. \ No newline at end of file +Kacper's version of Boot.dev's Notely apdp. \ No newline at end of file From 61449b6962b0acb47a79e8bbbbbbe1fe459e9c71 Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 13:52:24 +0100 Subject: [PATCH 03/19] =?UTF-8?q?Dodano=20konfiguracj=C4=99=20GitHub=20Act?= =?UTF-8?q?ions=20(ci.yml)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ci.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/ci.yml diff --git a/.github/ci.yml b/.github/ci.yml new file mode 100644 index 00000000000..a54d8248d54 --- /dev/null +++ b/.github/ci.yml @@ -0,0 +1,22 @@ +name: ci + +on: + pull_request: + branches: [main] + +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.25.1" + + - name: Force Failure + run: (exit 1) \ No newline at end of file From 05e0ff2479de850eba8c3f6c046adf30b626754f Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 13:57:17 +0100 Subject: [PATCH 04/19] Przeniesiono ci.yml do .github/workflows --- .github/{ => workflows}/ci.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{ => workflows}/ci.yml (100%) diff --git a/.github/ci.yml b/.github/workflows/ci.yml similarity index 100% rename from .github/ci.yml rename to .github/workflows/ci.yml From dae1b7c1fa528868daeb480903da03f678f3d7f1 Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 14:30:30 +0100 Subject: [PATCH 05/19] another test added --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a54d8248d54..7209fdb8050 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: "1.25.1" - - name: Force Failure - run: (exit 1) \ No newline at end of file + - name: version check + run: go version \ No newline at end of file From 89db7d5456ce2f2a31f2030aa745cf3d5c3c3d2f Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 15:11:56 +0100 Subject: [PATCH 06/19] Add unit tests for GetAPIKey function --- internal/auth/get_api_key_test.go | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 internal/auth/get_api_key_test.go diff --git a/internal/auth/get_api_key_test.go b/internal/auth/get_api_key_test.go new file mode 100644 index 00000000000..2db6392d4c6 --- /dev/null +++ b/internal/auth/get_api_key_test.go @@ -0,0 +1,39 @@ +package auth + +import ( + "net/http" + "testing" +) + +func TestGetAPIKey(t *testing.T) { + // Create headers with a correct Authorization header + headers := http.Header{} + headers.Set("Authorization", "ApiKey my-secret-key") + + // Call the function we're testing + apiKey, err := GetAPIKey(headers) + + // We expect NO error for a valid header + if err != nil { + t.Errorf("Expected no error, but got: %v", err) + } + + // We expect the API key to be "my-secret-key" + if apiKey != "my-secret-key" { + t.Errorf("Expected 'my-secret-key', but got: %s", apiKey) + } + headers2 := http.Header{} + // Call the function we're testing + apiKey2, err2 := GetAPIKey(headers2) + // We expect an error for missing header + if err2 == nil { + t.Errorf("Expected an error for missing header, but got none") + } + if apiKey2 != "" { + t.Errorf("Expected empty API key for missing header, but got: %s", apiKey2) + } + + +} + + From 52258e482d3377edc7493c0dfef0af784a2168f0 Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 15:14:12 +0100 Subject: [PATCH 07/19] breking some code to run tests --- .github/workflows/ci.yml | 4 ++-- main.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7209fdb8050..f692292024b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: "1.25.1" - - name: version check - run: go version \ No newline at end of file + - name: run tests + run: go test ./... \ No newline at end of file diff --git a/main.go b/main.go index 19d7366c5f7..adfd662f848 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ import ( _ "github.com/tursodatabase/libsql-client-go/libsql" ) -type apiConfig struct { +type apiConfig struct DB *database.Queries } From f9df7cfcdcb41ef41f05158b1ce29cd132ce5038 Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 15:15:28 +0100 Subject: [PATCH 08/19] fixing code --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index adfd662f848..19d7366c5f7 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ import ( _ "github.com/tursodatabase/libsql-client-go/libsql" ) -type apiConfig struct +type apiConfig struct { DB *database.Queries } From d8a7aeecdadccd996ec9168e51e4028c38938a50 Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 15:25:25 +0100 Subject: [PATCH 09/19] added coverage to tests --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f692292024b..734c67fcf45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.25.1" - name: run tests - run: go test ./... \ No newline at end of file + run: go test -cover ./... \ No newline at end of file From acd325f6b9dc0b8db543920df3f66fdab19e060d Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 15:27:32 +0100 Subject: [PATCH 10/19] added coverage to tests --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 734c67fcf45..08db21c4b9a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: "1.25.1" - - name: run tests + - name: go test run: go test -cover ./... \ No newline at end of file From 2dd68df350813c31ab2dd04c0f1e67e9b032e146 Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 15:28:53 +0100 Subject: [PATCH 11/19] added coverage to tests --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08db21c4b9a..eb8fed948b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.25.1" - name: go test - run: go test -cover ./... \ No newline at end of file + run: go test -cover ./... \ No newline at end of file From 56c371e285d72cb91f418ef3908ad018b004dc2a Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 15:33:15 +0100 Subject: [PATCH 12/19] added a BADGEgit add . --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5ed7434c091..76546328b9a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![BADGE](https://github.com///actions/workflows//badge.svg) + # learn-cicd-starter (Notely) This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev). From dffc7edf4893ad0353167b654717af27b5ad8341 Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 16:31:11 +0100 Subject: [PATCH 13/19] Added new Style-Test --- .github/workflows/ci.yml | 20 +++++++++++++++- internal/auth/get_api_key_test.go | 39 ++++++++++++++----------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb8fed948b4..de2ebe9e755 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,22 @@ jobs: go-version: "1.25.1" - name: go test - run: go test -cover ./... \ No newline at end of file + run: go test -cover ./... + + Style: # <--- TWÓJ NOWY JOB + name: Style + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.25.1" + + - name: Style + run: test -z $(go fmt ./...) + + \ No newline at end of file diff --git a/internal/auth/get_api_key_test.go b/internal/auth/get_api_key_test.go index 2db6392d4c6..153edce43b9 100644 --- a/internal/auth/get_api_key_test.go +++ b/internal/auth/get_api_key_test.go @@ -1,27 +1,27 @@ package auth import ( - "net/http" - "testing" + "net/http" + "testing" ) func TestGetAPIKey(t *testing.T) { - // Create headers with a correct Authorization header - headers := http.Header{} - headers.Set("Authorization", "ApiKey my-secret-key") - - // Call the function we're testing - apiKey, err := GetAPIKey(headers) - - // We expect NO error for a valid header - if err != nil { - t.Errorf("Expected no error, but got: %v", err) - } - - // We expect the API key to be "my-secret-key" - if apiKey != "my-secret-key" { - t.Errorf("Expected 'my-secret-key', but got: %s", apiKey) - } + // Create headers with a correct Authorization header + headers := http.Header{} + headers.Set("Authorization", "ApiKey my-secret-key") + + // Call the function we're testing + apiKey, err := GetAPIKey(headers) + + // We expect NO error for a valid header + if err != nil { + t.Errorf("Expected no error, but got: %v", err) + } + + // We expect the API key to be "my-secret-key" + if apiKey != "my-secret-key" { + t.Errorf("Expected 'my-secret-key', but got: %s", apiKey) + } headers2 := http.Header{} // Call the function we're testing apiKey2, err2 := GetAPIKey(headers2) @@ -33,7 +33,4 @@ func TestGetAPIKey(t *testing.T) { t.Errorf("Expected empty API key for missing header, but got: %s", apiKey2) } - } - - From 5f2e17ce19bc6e3bced497ac2cca8ca9bc18a0a5 Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 16:42:52 +0100 Subject: [PATCH 14/19] addig static check test, and a bug in code for tests --- .github/workflows/ci.yml | 6 ++++++ main.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de2ebe9e755..4b0cfa53545 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,4 +37,10 @@ jobs: - name: Style run: test -z $(go fmt ./...) + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest + + - name: Run staticcheck + run: staticcheck ./... + \ No newline at end of file diff --git a/main.go b/main.go index 19d7366c5f7..e546112a05a 100644 --- a/main.go +++ b/main.go @@ -96,3 +96,8 @@ func main() { log.Printf("Serving on port: %s\n", port) log.Fatal(srv.ListenAndServe()) } + +func unused() { + // this function does nothing + // and is called nowhere +} \ No newline at end of file From 3c328999b3d5e161b8d39a48914ed72bed8937ad Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 16:44:46 +0100 Subject: [PATCH 15/19] addig static check test --- main.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/main.go b/main.go index e546112a05a..dd9f84f90ea 100644 --- a/main.go +++ b/main.go @@ -95,9 +95,4 @@ func main() { log.Printf("Serving on port: %s\n", port) log.Fatal(srv.ListenAndServe()) -} - -func unused() { - // this function does nothing - // and is called nowhere } \ No newline at end of file From c361cb4b8d8f55128d58ed9bd4cfb196d7d2b267 Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 16:45:42 +0100 Subject: [PATCH 16/19] addig static check test --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index dd9f84f90ea..19d7366c5f7 100644 --- a/main.go +++ b/main.go @@ -95,4 +95,4 @@ func main() { log.Printf("Serving on port: %s\n", port) log.Fatal(srv.ListenAndServe()) -} \ No newline at end of file +} From f3be15af79d9b8f004dc6121350642e72d9cab51 Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 16:59:52 +0100 Subject: [PATCH 17/19] security checks --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b0cfa53545..fd6dae7ca27 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,12 @@ jobs: - name: go test run: go test -cover ./... + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest + + - name: Run gosec + run: gosec ./... + Style: # <--- TWÓJ NOWY JOB name: Style runs-on: ubuntu-latest From d19d8f52235a8375203c0ed5bbae615249b7bd1a Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 17:11:12 +0100 Subject: [PATCH 18/19] . --- json.go | 7 ++++++- main.go | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/json.go b/json.go index 1e6e7985e18..833b267d955 100644 --- a/json.go +++ b/json.go @@ -30,5 +30,10 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) { return } w.WriteHeader(code) - w.Write(dat) + _, err = w.Write(dat) // W Go, ignorujemy liczbę bajtów za pomocą _ + if err != nil { + // Jeśli zapis się nie uda, po prostu logujemy to. Klient i tak nie otrzyma nic więcej. + log.Println("error writing response:", err) + return + } } diff --git a/main.go b/main.go index 19d7366c5f7..02902178399 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "os" + "time" "github.com/go-chi/chi" "github.com/go-chi/cors" @@ -89,8 +90,11 @@ func main() { router.Mount("/v1", v1Router) srv := &http.Server{ - Addr: ":" + port, - Handler: router, + Addr: ":" + port, + Handler: router, + ReadHeaderTimeout: 5 * time.Second, // Dajemy 5 sekund na nagłówki + WriteTimeout: 5 * time.Second, // Dajemy 5 sekund na zapis odpowiedzi + IdleTimeout: 60 * time.Second, // Dajmy 60 sekund na utrzymanie bezczynnego połączenia } log.Printf("Serving on port: %s\n", port) From 4f06b6707ed928cbce4ccbd5ffe525c2a0629d28 Mon Sep 17 00:00:00 2001 From: KMlynkowiak Date: Tue, 16 Dec 2025 17:32:15 +0100 Subject: [PATCH 19/19] feat: Added Continuous Delivery workflow cd.yml --- .github/workflows/cd.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 00000000000..b8da6a2ac66 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,21 @@ +name: cd + +on: + push: + branches: [main] + +jobs: + deploy: + name: deploy + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.25.1" + + - name: Build app + run: scripts/buildprod.sh