Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
548004e
add myself to README.md
Kenedy228 Dec 30, 2025
6c2e0f4
add ci.yml
Kenedy228 Dec 30, 2025
c83480d
delete Force Failure step in ci.yml, added Check version of Go step
Kenedy228 Dec 30, 2025
d4f85b1
delete Checking version step from ci.yml, added Tests step. Added tes…
Kenedy228 Dec 30, 2025
547a8dc
fixed invalid header for Authorization in internal/auth/auth.go
Kenedy228 Dec 30, 2025
7ada4a0
add test coverage flag for go test in ci.yml
Kenedy228 Dec 30, 2025
0404730
add dynamic test badge in README.md file
Kenedy228 Dec 30, 2025
5d0b7c3
add style checks into ci.yml
Kenedy228 Dec 30, 2025
e9000ef
Merge pull request #2 from Kenedy228/addtests
Kenedy228 Dec 30, 2025
2b10d8b
add linter check in ci.yml and an unused function
Kenedy228 Dec 30, 2025
429e561
add linter check in ci.yml and an unused function
Kenedy228 Dec 30, 2025
a53ee0d
remove unused function
Kenedy228 Dec 30, 2025
91847a0
Merge pull request #4 from Kenedy228/addtests
Kenedy228 Dec 30, 2025
e3ff652
add gosec support for ci pipeline
Kenedy228 Dec 30, 2025
d925c19
add read header timeout for server and resolve json errors
Kenedy228 Dec 30, 2025
6feb14f
Merge pull request #5 from Kenedy228/addtests
Kenedy228 Dec 30, 2025
787a1b3
add gosec to tests job in ci.yml
Kenedy228 Dec 30, 2025
f10678b
Merge pull request #6 from Kenedy228/addtests
Kenedy228 Dec 30, 2025
ce8cf86
Revert "add gosec to tests job in ci.yml"
Kenedy228 Dec 30, 2025
5001995
Merge pull request #7 from Kenedy228/revert-6-addtests
Kenedy228 Dec 30, 2025
d81b774
changed README.md
Kenedy228 Dec 30, 2025
801f2d9
Merge pull request #8 from Kenedy228/addtests
Kenedy228 Dec 30, 2025
820d21a
changed README.md
Kenedy228 Dec 30, 2025
196dad8
Merge pull request #9 from Kenedy228/addtests
Kenedy228 Dec 30, 2025
a825c8d
changed ci.yml name of gosec
Kenedy228 Dec 30, 2025
2af5fa7
Revert "add gosec to tests job in ci.yml"
Kenedy228 Dec 30, 2025
68b0c80
changed ci.yml name of gosec
Kenedy228 Dec 30, 2025
4c0d952
foo
Kenedy228 Dec 30, 2025
d05e0c7
Merge branch 'main' into addtests
Kenedy228 Dec 30, 2025
7b24e62
add cd.yml
Kenedy228 Dec 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: cd.yml
on:
push:
branches: [main]
jobs:
name: Deploy
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25.1"

- name: Build the app
run: ./scripts/buildprod.sh
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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: Run tests
run: go test ./... -cover

- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest

- name: Run gosec
run: gosec ./...

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.25.1"

- name: Install staticheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Style
run: test -z $(go fmt ./...)

- name: Linter
run: staticcheck ./...
10 changes: 10 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/go.imports.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/learn-cicd-starter.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# learn-cicd-starter (Notely)
![all tests badge](https://github.com/<OWNER>/<REPOSITORY>/actions/workflows/<WORKFLOW_FILE>/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).

Expand All @@ -21,3 +23,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!

Kenedy228's version of Boot.dev's Notely app.
53 changes: 53 additions & 0 deletions internal/auth/tests/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package tests

import (
"net/http"
"testing"

"github.com/bootdotdev/learn-cicd-starter/internal/auth"
)

func TestAuthWithValidHeaders(t *testing.T) {
keys := []string{
"ApiKey 123",
"ApiKey abc",
"ApiKey ZZZHDAWHDASDRE",
}

expected := []string{
"123",
"abc",
"ZZZHDAWHDASDRE",
}

for i := range keys {
headers := http.Header{}
headers.Add("Authorization", keys[i])

key, err := auth.GetAPIKey(headers)

if err != nil {
t.Fatalf("An error occured while generating API key: %v", err)
}

if key != expected[i] {
t.Fatalf("An error occured while generating API key. Expected %v, got %v", expected[i], key)
}
}
}

func TestAuthWitnInvalidHeaders(t *testing.T) {
keys := []string{
"Bearer 123",
"Choco 3333",
"Hi asdfg",
}

for i := range keys {
headers := http.Header{}
headers.Add("Authorization", keys[i])
if _, err := auth.GetAPIKey(headers); err == nil {
t.Fatal("Expected error while generating API key. Got nil")
}
}
}
6 changes: 5 additions & 1 deletion json.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
return
}
w.WriteHeader(code)
w.Write(dat)
_, err = w.Write(dat)
if err != nil {
w.WriteHeader(500)
return
}
}
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net/http"
"os"
"time"

"github.com/go-chi/chi"
"github.com/go-chi/cors"
Expand Down Expand Up @@ -89,8 +90,9 @@ func main() {

router.Mount("/v1", v1Router)
srv := &http.Server{
Addr: ":" + port,
Handler: router,
Addr: ":" + port,
Handler: router,
ReadHeaderTimeout: time.Minute,
}

log.Printf("Serving on port: %s\n", port)
Expand Down