Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3521704
Add name to README
sadiaaschrafi Jan 7, 2026
93b97f4
ci
sadiaaschrafi Jan 7, 2026
264b4fa
insert the initila code in to ci.yml
sadiaaschrafi Jan 7, 2026
d058cc7
change froce failure to force success
sadiaaschrafi Jan 7, 2026
c094828
change back to force failure
sadiaaschrafi Jan 7, 2026
1a1a979
change force failure to go version
sadiaaschrafi Jan 7, 2026
7252bc2
Add unit tests for GetAPIKey function
sadiaaschrafi Jan 7, 2026
1d52f26
Update CI to run tests and add failing test
sadiaaschrafi Jan 7, 2026
fb718b0
Fix tests - remove forced failure
sadiaaschrafi Jan 7, 2026
6f22b6d
Add code coverage reporting to CI
sadiaaschrafi Jan 7, 2026
9273f68
Add CI badge to README
sadiaaschrafi Jan 8, 2026
1915568
use REDME.md
sadiaaschrafi Jan 9, 2026
b24603d
Add Style job for formatting checks and update README badge
sadiaaschrafi Jan 9, 2026
cd8f478
Fix Style job name and use test -z command
sadiaaschrafi Jan 9, 2026
43fdc22
Fix Style job with test -z command
sadiaaschrafi Jan 9, 2026
5953203
Fix duplicate step name in Style job
sadiaaschrafi Jan 9, 2026
7975e33
Add style job for go fmt
sadiaaschrafi Jan 11, 2026
9203f59
Fix Style job and format code
sadiaaschrafi Jan 11, 2026
c165d86
Fix tests job
sadiaaschrafi Jan 12, 2026
eb97314
Fix tests job
sadiaaschrafi Jan 12, 2026
6e220aa
remove duplicate code from ci.yml
sadiaaschrafi Jan 12, 2026
8b6f0fb
restor main.go
sadiaaschrafi Jan 12, 2026
0b8233e
fixed the style job
sadiaaschrafi Jan 12, 2026
48fd7cf
fix fomatting main.go
sadiaaschrafi Jan 12, 2026
5d5d773
changes added
sadiaaschrafi Jan 13, 2026
9817a66
Add gosec security checks to CI
sadiaaschrafi Jan 13, 2026
128ed22
Add ReadHeaderTimeout to HTTP server
sadiaaschrafi Jan 13, 2026
6c955a0
Handle error when writing JSON response
sadiaaschrafi Jan 13, 2026
b7fa258
Fix gosec G104 by handling http response write error
sadiaaschrafi Jan 13, 2026
41843b1
Fix gosec G104 and define errorResponse
sadiaaschrafi Jan 13, 2026
0a7a148
changes is fixed
sadiaaschrafi Jan 14, 2026
27e50c5
Add gosec security scanning to CI
sadiaaschrafi Jan 14, 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
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
tests:
name: Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.21'

- name: Run tests
run: go test ./... --cover

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

- name: Run gosec security scan
run: gosec ./...
30 changes: 12 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
# learn-cicd-starter (Notely)
[![CI Status](https://github.com/sadiaaschrafi/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/sadiaaschrafi/learn-cicd-starter/actions)

This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev).
# learn-cicd-starter

## Local Development
This is a starter project for learning CI/CD concepts.

Make sure you're on Go version 1.22+.
## Features
- Automated testing with Go
- CI/CD pipeline with GitHub Actions
- Code formatting checks

Create a `.env` file in the root of the project with the following contents:
## Getting Started
1. Clone the repository
2. Run `go mod tidy`
3. Run `go test ./...` to run tests

```bash
PORT="8080"
```

Run the server:

```bash
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!
sadiaaschrafi's version of Boot.dev's Notely app.
38 changes: 38 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package auth

import (
"net/http"
"testing"
)

func TestGetAPIKey(t *testing.T) {
t.Run("returns API key when header is valid", func(t *testing.T) {
headers := http.Header{}
headers.Set("Authorization", "ApiKey test123")

key, err := GetAPIKey(headers)

if err != nil {
t.Errorf("Expected no error, got %v", err)
}
if key != "test123" {
t.Errorf("Expected 'test123', got %s", key)
}
})

t.Run("returns error when no authorization header", func(t *testing.T) {
headers := http.Header{}

key, err := GetAPIKey(headers)

if err == nil {
t.Error("Expected error, got nil")
}
if err != ErrNoAuthHeaderIncluded {
t.Errorf("Expected ErrNoAuthHeaderIncluded, got %v", err)
}
if key != "" {
t.Errorf("Expected empty key, got %s", key)
}
})
}
2 changes: 0 additions & 2 deletions internal/database/models.go

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

29 changes: 14 additions & 15 deletions json.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,28 @@ import (
"net/http"
)

func respondWithError(w http.ResponseWriter, code int, msg string, logErr error) {
if logErr != nil {
log.Println(logErr)
}
if code > 499 {
log.Printf("Responding with 5XX error: %s", msg)
}
type errorResponse struct {
Error string `json:"error"`
}
respondWithJSON(w, code, errorResponse{
Error: msg,
})
type errorResponse struct {
Error string `json:"error"`
}

func respondWithError(w http.ResponseWriter, code int, msg string) {
respondWithJSON(w, code, errorResponse{
Error: msg,
})
}

func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
w.Header().Set("Content-Type", "application/json")

dat, err := json.Marshal(payload)
if err != nil {
log.Printf("Error marshalling JSON: %s", err)
w.WriteHeader(500)
w.WriteHeader(http.StatusInternalServerError)
return
}

w.WriteHeader(code)
w.Write(dat)
if _, err := w.Write(dat); err != nil {
log.Println("error writing response:", err)
}
}
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: 5 * time.Second,
}

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