Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0eb23e8
Update README
ArchAngel77 May 12, 2026
971df65
created .github dir, workflows dir, and ci.yml file
ArchAngel77 May 12, 2026
83a607c
updated check
ArchAngel77 May 12, 2026
5729c5e
updated ci.yml file for testing
ArchAngel77 May 13, 2026
b2334fb
break auth logic with potato
ArchAngel77 May 13, 2026
77e7b61
alternate test change
ArchAngel77 May 13, 2026
2235586
fixed
ArchAngel77 May 13, 2026
8d45ed4
added -cover to test input
ArchAngel77 May 13, 2026
df90700
added badge to README.md
ArchAngel77 May 13, 2026
23d6c22
add CI badge to README
ArchAngel77 May 13, 2026
ee85622
added staticcheck
ArchAngel77 May 14, 2026
6e03a1f
updated yml test
ArchAngel77 May 14, 2026
1a6698c
remove unused function
ArchAngel77 May 14, 2026
556b497
remove unused function
ArchAngel77 May 14, 2026
9c41867
updated formatting in yml
ArchAngel77 May 14, 2026
6e81b2a
trigger ci
ArchAngel77 May 14, 2026
fc95c09
trigger ci
ArchAngel77 May 14, 2026
cbef9c4
trigger ci
ArchAngel77 May 14, 2026
1d1a13d
retrigger pr checks
ArchAngel77 May 14, 2026
a4747b7
fix ci style job
ArchAngel77 May 14, 2026
1ac7b9c
add push trigger for ci
ArchAngel77 May 14, 2026
d3f79c4
format go files
ArchAngel77 May 14, 2026
e0d398e
remove push trigger
ArchAngel77 May 14, 2026
624a4a9
added formating to ci.yml
ArchAngel77 May 15, 2026
d904297
added gosec
ArchAngel77 May 15, 2026
0f9bd73
corrected gosec found errors
ArchAngel77 May 15, 2026
82fcab5
corrections to previous problems
ArchAngel77 May 15, 2026
0d8ff8c
fix ci.yml
ArchAngel77 May 15, 2026
1663120
trigger ci
ArchAngel77 May 15, 2026
93dd6d9
indentations correction
ArchAngel77 May 15, 2026
c569064
fix gosec issues in main.go
ArchAngel77 May 15, 2026
320c144
added to main.go, need to take away
ArchAngel77 May 16, 2026
7f3f1c9
corrected
ArchAngel77 May 16, 2026
2812eb8
trigger ci run
ArchAngel77 May 16, 2026
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
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 unit 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: Check formatting
run: test -z $(go fmt ./...)

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

- name: Run staticcheck
run: staticcheck ./...

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

![CI](https://github.com/ArchAngel77/learn-cicd-starter/actions/workflows/ci.yml/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 +24,6 @@ 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!

Jordan's version of Boot.dev's Notely app
# trigger
2 changes: 1 addition & 1 deletion internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func GetAPIKey(headers http.Header) (string, error) {
return "", ErrNoAuthHeaderIncluded
}
splitAuth := strings.Split(authHeader, " ")
if len(splitAuth) < 2 || splitAuth[0] != "ApiKey" {
if len(splitAuth) < 2 || splitAuth[0] != "apiKey" {
return "", errors.New("malformed authorization header")
}

Expand Down
41 changes: 41 additions & 0 deletions internal/auth/get_api_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package auth

import (
"net/http"
"strings"
"testing"
)

func TestAPIKey(t *testing.T) {
// 1. Define the 'table' of test cases
tests := []struct {
name string
inputHeader http.Header
expectedKey string
expectedError string
}{
{name: "valid api key",
inputHeader: http.Header{
"Authorization": []string{"ApiKey secret-sauce"},
},
expectedKey: "secret-sauce",
expectedError: "",
},
}

// 2. Iterate over the table
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
apiKey, err := GetAPIKey(tt.inputHeader)
if err != nil {
if !strings.Contains(err.Error(), tt.expectedError) {
t.Errorf("expected error containing %s, got %v", tt.expectedError, err)
}
return
}
if apiKey != tt.expectedKey {
t.Errorf("expected %s, got %s", tt.expectedKey, apiKey)
}
})
}
}
5 changes: 4 additions & 1 deletion json.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
return
}
w.WriteHeader(code)
w.Write(dat)
_, err = w.Write(dat)
if err != nil {
log.Printf("Critical error writing response: %s" ,err)
}
}
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"log"
"net/http"
"os"
"strconv"
"time"

"github.com/go-chi/chi"
"github.com/go-chi/cors"
Expand Down Expand Up @@ -91,8 +93,9 @@ func main() {
srv := &http.Server{
Addr: ":" + port,
Handler: router,
ReadHeaderTimeout: time.Second * 5,
}

log.Printf("Serving on port: %s\n", port)
log.Printf("Serving on port: %s\n", strconv.Quote(port))
log.Fatal(srv.ListenAndServe())
}