From 0a6e94b2a2060e9b02e6c04ff8562196a959081d Mon Sep 17 00:00:00 2001 From: Amil Date: Sat, 5 Sep 2026 20:19:14 +0200 Subject: [PATCH 01/18] Added text on the end of README (#1) * Added text on the end of README * Created CI * Changed directory name * Returning success * Broken on purpose * Fixed * Added -cover for code coverage * Added dynamic badge * Fixing badge --- .github/ci.yml | 19 ++++++++++ .github/workflows/ci.yml | 21 +++++++++++ README.md | 3 ++ internal/auth/get_api_key_test.go | 61 +++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 .github/ci.yml create mode 100644 .github/workflows/ci.yml create mode 100644 internal/auth/get_api_key_test.go diff --git a/.github/ci.yml b/.github/ci.yml new file mode 100644 index 00000000000..5bc77b0a01d --- /dev/null +++ b/.github/ci.yml @@ -0,0 +1,19 @@ +name: ci +on: + pull_request: + branches: [ main ] +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: "1.27.1" + - name: Force Failure + run: (exit 1) + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..7f017cfca83 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,21 @@ +name: ci +on: + pull_request: + branches: [main] + +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v6 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: "1.27.1" + + - name: Success + run: go test ./... -cover diff --git a/README.md b/README.md index eb5dca97a5a..22ee49a7a99 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![CI Status](https://github.com/amilujinovic/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/amilujinovic/learn-cicd-starter/actions) + # 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). @@ -21,3 +23,4 @@ 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! +Amil's version of Boot.dev's Notely app diff --git a/internal/auth/get_api_key_test.go b/internal/auth/get_api_key_test.go new file mode 100644 index 00000000000..41c632eded5 --- /dev/null +++ b/internal/auth/get_api_key_test.go @@ -0,0 +1,61 @@ +package auth + +import ( + "net/http" + "testing" +) + +func TestGetAPIKey(t *testing.T) { + tests := []struct { + name string + headers http.Header + expectedKey string + expectError bool + }{ + { + name: "Validni API ključ", + headers: http.Header{ + "Authorization": []string{"ApiKey moj_tajni_kljuc_123"}, + }, + expectedKey: "moj_tajni_kljuc_123", + expectError: false, + }, + { + name: "Nedostaje Authorization zaglavlje", + headers: http.Header{}, + expectedKey: "", + expectError: true, + }, + { + name: "Pogrešan format - nedostaje ApiKey prefiks", + headers: http.Header{ + "Authorization": []string{"samo_kljuc"}, + }, + expectedKey: "", + expectError: true, + }, + { + name: "Pogrešna šema - koristi Bearer umesto ApiKey", + headers: http.Header{ + "Authorization": []string{"Bearer neki_token"}, + }, + expectedKey: "", + expectError: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + key, err := GetAPIKey(tt.headers) + + if (err != nil) != tt.expectError { + t.Errorf("GetAPIKey() greška = %v, očekivana greška %v", err, tt.expectError) + return + } + + if key != tt.expectedKey { + t.Errorf("GetAPIKey() = %v, očekivano %v", key, tt.expectedKey) + } + }) + } +} From 2603e4bfd0a0489b3b6d0a2c04cfc2da976dfc0c Mon Sep 17 00:00:00 2001 From: Amil Date: Sat, 5 Sep 2026 21:44:54 +0200 Subject: [PATCH 02/18] Added formating (#2) * Added text on the end of README * Created CI * Changed directory name * Returning success * Broken on purpose * Fixed * Added -cover for code coverage * Added dynamic badge * Fixing badge * Set up separate formating job * Fixed space error * aa * Space problem fixed in line 6 * Now it will work --- .github/workflows/ci.yml | 25 +++++++++++++++---------- Re | 0 2 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 Re diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f017cfca83..1c388bcb5d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,21 +1,26 @@ -name: ci -on: - pull_request: - branches: [main] - jobs: tests: name: Tests runs-on: ubuntu-latest - steps: - name: Check out code - uses: actions/checkout@v6 - + uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v6 + uses: actions/setup-go@v5 with: go-version: "1.27.1" - - name: Success run: go test ./... -cover + + style: + 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.27.1" + - name: Formating + run: test -z $(go fmt ./...) \ No newline at end of file diff --git a/Re b/Re new file mode 100644 index 00000000000..e69de29bb2d From 322dfc2b3770f7ac15f949eaf8815d2af547e9af Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sat, 5 Sep 2026 17:57:26 +0200 Subject: [PATCH 03/18] Changed directory name --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c388bcb5d2..a5caed7cad1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,3 +1,9 @@ +name: CI + +on: + pull_request: + branches: [ "main" ] + jobs: tests: name: Tests @@ -23,4 +29,4 @@ jobs: with: go-version: "1.27.1" - name: Formating - run: test -z $(go fmt ./...) \ No newline at end of file + run: test -z $(go fmt ./...) From 632d540de38e4a73bb5102da6128917fb7223d3f Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sat, 5 Sep 2026 18:02:45 +0200 Subject: [PATCH 04/18] Returning success --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5caed7cad1..0be5157c0d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,8 @@ + name: CI + +name: ci on: pull_request: branches: [ "main" ] @@ -30,3 +33,5 @@ jobs: go-version: "1.27.1" - name: Formating run: test -z $(go fmt ./...) + - name: Success + run: (exit 0) From 47efa64f848fca7bf0605949a84a227bcde3216d Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sat, 5 Sep 2026 20:06:47 +0200 Subject: [PATCH 05/18] Added -cover for code coverage --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0be5157c0d3..4bf24e75b2a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,6 @@ jobs: go-version: "1.27.1" - name: Success run: go test ./... -cover - style: name: Style runs-on: ubuntu-latest From 6db0a9d382b382ca91dc9743eb684a505b6601b0 Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sat, 5 Sep 2026 20:12:38 +0200 Subject: [PATCH 06/18] Added dynamic badge --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 22ee49a7a99..15484160ea9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ + [![CI Status](https://github.com/amilujinovic/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/amilujinovic/learn-cicd-starter/actions) +[![CI Status](https://github.com///actions/workflows//badge.svg)](https://github.com///actions) + + # 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 4ee0906965832b3615889660b375ec0099d64e86 Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sat, 5 Sep 2026 20:16:34 +0200 Subject: [PATCH 07/18] Fixing badge --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 15484160ea9..c74103f8d53 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,13 @@ + [![CI Status](https://github.com/amilujinovic/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/amilujinovic/learn-cicd-starter/actions) [![CI Status](https://github.com///actions/workflows//badge.svg)](https://github.com///actions) +[![CI Status](https://github.com/amilujinovic/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/amilujinovic/learn-cicd-starter/actions) + + # 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 6fbac72ac2258cd8f4ed404be3487a5e56823c6c Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sat, 5 Sep 2026 20:32:22 +0200 Subject: [PATCH 08/18] Set up separate formating job --- ci.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 ci.yml diff --git a/ci.yml b/ci.yml new file mode 100644 index 00000000000..e69de29bb2d From 25b82599828f238273b48b5bc683e03e18117b14 Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sat, 5 Sep 2026 20:42:07 +0200 Subject: [PATCH 09/18] aa --- ci.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 ci.yml diff --git a/ci.yml b/ci.yml deleted file mode 100644 index e69de29bb2d..00000000000 From 440cded3e91174b3e871fa32b5548bbdaf034e4d Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sat, 5 Sep 2026 21:47:57 +0200 Subject: [PATCH 10/18] Trigger CI From 0ea9341de6507123928d3495ed9d6cca3d903a41 Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sat, 5 Sep 2026 21:48:40 +0200 Subject: [PATCH 11/18] Trigger CI From 27c7144cfd2457eb6ca7fa348d58e400927ccfcf Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sat, 5 Sep 2026 21:57:20 +0200 Subject: [PATCH 12/18] Force CI trigger From e15f88bbe47e0e0b35d7eadb1a27cde1c1561a77 Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sat, 5 Sep 2026 21:59:32 +0200 Subject: [PATCH 13/18] =?UTF-8?q?Uklonjen=20suvi=C5=A1an=20ci.yml=20fajl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ci.yml | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .github/ci.yml diff --git a/.github/ci.yml b/.github/ci.yml deleted file mode 100644 index 5bc77b0a01d..00000000000 --- a/.github/ci.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: ci -on: - pull_request: - branches: [ main ] -jobs: - tests: - name: Tests - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v6 - - - name: Set up Go - uses: actions/setup-go@v6 - with: - go-version: "1.27.1" - - name: Force Failure - run: (exit 1) - From 468b68c3e6921de6822bd0f9a80e696f1800c517 Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sat, 5 Sep 2026 22:12:55 +0200 Subject: [PATCH 14/18] I hope last --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4bf24e75b2a..4563a23276d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,3 @@ - -name: CI - - name: ci on: pull_request: From d0c5a5b6bc318b3db31d0f812990c53a1234b193 Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sun, 6 Sep 2026 15:42:13 +0200 Subject: [PATCH 15/18] Trying linting staticcheck --- .github/workflows/ci.yml | 2 ++ go.mod | 2 +- main.go | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4563a23276d..77218aa87dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,3 +30,5 @@ jobs: run: test -z $(go fmt ./...) - name: Success run: (exit 0) + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest diff --git a/go.mod b/go.mod index edca50dbb9b..7380acf8a3a 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/bootdotdev/learn-cicd-starter -go 1.27.1 +go 1.22.2 require ( github.com/go-chi/chi v1.5.4 diff --git a/main.go b/main.go index 19d7366c5f7..0b4f07b1e1d 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,10 @@ type apiConfig struct { //go:embed static/* var staticFiles embed.FS - +func unused() { +// this function does nothing +//and is called nowhere +} func main() { err := godotenv.Load(".env") if err != nil { From 2985745793462fa5ef6956aaafeac63f1cf7a408 Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sun, 6 Sep 2026 15:45:02 +0200 Subject: [PATCH 16/18] Linting v2 --- main.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main.go b/main.go index 0b4f07b1e1d..3c235761932 100644 --- a/main.go +++ b/main.go @@ -23,10 +23,6 @@ type apiConfig struct { //go:embed static/* var staticFiles embed.FS -func unused() { -// this function does nothing -//and is called nowhere -} func main() { err := godotenv.Load(".env") if err != nil { From 3485f1c4096c76fe18cf9efd9a0f520cff1e727b Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sun, 6 Sep 2026 15:49:23 +0200 Subject: [PATCH 17/18] Format code with go fmt --- main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main.go b/main.go index 3c235761932..19d7366c5f7 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ type apiConfig struct { //go:embed static/* var staticFiles embed.FS + func main() { err := godotenv.Load(".env") if err != nil { From e182cfb24d2d68d3cfd65b42a920c12818d1919d Mon Sep 17 00:00:00 2001 From: amillujinovic Date: Sun, 6 Sep 2026 16:05:14 +0200 Subject: [PATCH 18/18] Adding gosec --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77218aa87dd..b7c58bff85b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,3 +32,6 @@ jobs: run: (exit 0) - name: Install staticcheck run: go install honnef.co/go/tools/cmd/staticcheck@latest + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest +