Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
07c4843
first push
AmanT776 Aug 12, 2026
728e226
feat: add github workflows
AmanT776 Aug 12, 2026
fdda726
feat: change the last action to display go version
AmanT776 Aug 12, 2026
4e56225
fix: update command to check Go version in CI workflow
AmanT776 Aug 12, 2026
63d9304
feat: wrote test for auth and added it on the ci
AmanT776 Aug 12, 2026
9ca0fd8
feat:- added test step
AmanT776 Aug 12, 2026
bed2d12
fix: update authorization header validation in GetAPIKey function
AmanT776 Aug 12, 2026
25ee067
fix: rename test function to follow Go naming conventions
AmanT776 Aug 12, 2026
99783c8
fix: update authorization header type check in GetAPIKey function
AmanT776 Aug 12, 2026
9de09d6
fix: add coverage flag to go test command in CI workflow
AmanT776 Aug 12, 2026
5d50d4a
fix: update formatting in README for clarity
AmanT776 Aug 12, 2026
88da985
fix: update test badge link in README for accuracy
AmanT776 Aug 12, 2026
068c864
fix: correct test badge link in README for accuracy
AmanT776 Aug 12, 2026
e4761d0
fix: add lint and format job to CI workflow
AmanT776 Aug 12, 2026
0471075
fix: format CI workflow for consistency and clarity
AmanT776 Aug 13, 2026
bbd28b0
fix: improve formatting and structure of CI workflow
AmanT776 Aug 13, 2026
92a5484
fix: correct test function closure in GetAPIKey test
AmanT776 Aug 13, 2026
0bd3ee1
fix: rename lint-and-format job to Style for clarity
AmanT776 Aug 13, 2026
aa03999
fix: add staticcheck installation and linting check to CI workflow
AmanT776 Aug 13, 2026
0a875bc
fix: update staticcheck installation to specific version 1.26.0
AmanT776 Aug 13, 2026
361e2b6
fix: update staticcheck installation to version 0.7.0
AmanT776 Aug 13, 2026
1ac986e
fix: format unused function for consistency
AmanT776 Aug 13, 2026
da8c4c9
fix: remove unused function to improve code clarity
AmanT776 Aug 13, 2026
e5b399d
fix: remove unnecessary blank line for improved readability
AmanT776 Aug 13, 2026
f467f0a
fix: add security tests with gosec installation and execution
AmanT776 Aug 13, 2026
4a43e02
fix: rename security job to security-scans for consistency
AmanT776 Aug 13, 2026
7b56ed1
fix: format security job steps for consistency
AmanT776 Aug 13, 2026
bfc7eb8
fix: correct typo in gosec installation command
AmanT776 Aug 13, 2026
28d6acd
fix: streamline Gosec security scanner setup in CI workflow
AmanT776 Aug 13, 2026
96d2395
fix: update Gosec scanner args to include vendor module
AmanT776 Aug 13, 2026
08d569c
fix: update Gosec scanner args to remove vendor module specification
AmanT776 Aug 13, 2026
0956e45
fix: improve CI workflow by correcting job names and adding missing s…
AmanT776 Aug 13, 2026
b8d2b68
fix: enhance logging setup and improve server startup message
AmanT776 Aug 13, 2026
d71cb1b
fix: handle error when writing JSON response
AmanT776 Aug 13, 2026
2e7edca
fix: correct formatting in respondWithJSON function
AmanT776 Aug 13, 2026
3a4fd59
fix: rename security scan job to align with naming conventions
AmanT776 Aug 13, 2026
91c1144
feat: add continuous deployment workflow for main branch
AmanT776 Aug 14, 2026
bfb7758
fix: update deployment workflow to correct job structure and maintain…
AmanT776 Aug 14, 2026
59822fb
fix: add job name to deployment workflow for clarity
AmanT776 Aug 14, 2026
af80b32
fix: correct job name for security scans in CI workflow
AmanT776 Aug 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
25 changes: 25 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: cd

on:
push:
branches: [main]

jobs:
build-and-deploy:
name: Deploy
runs-on: ubuntu-latest

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

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.26.0"

- name: Make script executable
run: chmod +x ./scripts/buildprod.sh

- name: Build app
run: ./scripts/buildprod.sh
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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.26.0"

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

security-scans:
name: Secuirty Tests
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v6

- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: ./...

lint-and-format:
name: Style
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.26.0"

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

- name: Format code
run: test -z "$(go fmt ./...)"

- name: Check linting
run: staticcheck ./...
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![test badge](https://github.com/AmanT776/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/AmanT776/learn-cicd-starter/actions/workflows/ci.yml)

# 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 @@ -18,6 +20,8 @@ Run the server:
go build -o notely && ./notely
```

*This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`.
_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!

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

import (
"errors"
"net/http"
"testing"

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

func TestApiKey(t *testing.T) {
tests := []struct {
name string
headers http.Header
expectedKey string
expectedError error
}{
{
name: "successfull extraction with ApiKey scheme",
headers: http.Header{
"Authorization": []string{"ApiKey secret-token-123"},
},
expectedKey: "secret-token-123",
expectedError: nil,
},
{
name: "malformed header - wrong scheme prefix",
headers: http.Header{
"Authorization": []string{"Bearer secret-token-123"},
},
expectedKey: "",
expectedError: errors.New("malformed authorization header"),
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
key, err := auth.GetAPIKey(tc.headers)

if tc.expectedError != nil {
if err == nil {
t.Fatalf("expected error %v, got nil", tc.expectedError)
}

// Use errors.Is for sentinel errors, or string comparison for generic errors
if errors.Is(tc.expectedError, auth.ErrNoAuthHeaderIncluded) {
if !errors.Is(err, auth.ErrNoAuthHeaderIncluded) {
t.Errorf("expected sentinel error %v, got %v", tc.expectedError, err)
}
} else if err.Error() != tc.expectedError.Error() {
t.Errorf("expected error message %q, got %q", tc.expectedError.Error(), err.Error())
}
} else {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}

// 2. Handle key assertions
if key != tc.expectedKey {
t.Errorf("expected key %q, got %q", tc.expectedKey, key)
}
})
}
}
4 changes: 3 additions & 1 deletion json.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
return
}
w.WriteHeader(code)
w.Write(dat)
if _, err := w.Write(dat); err != nil {
log.Println(err)
}
}
13 changes: 10 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package main
import (
"database/sql"
"embed"
"fmt"
"io"
"log"
"log/slog"
"net/http"
"os"
"time"

"github.com/go-chi/chi"
"github.com/go-chi/cors"
Expand All @@ -25,6 +28,9 @@ type apiConfig struct {
var staticFiles embed.FS

func main() {
logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: slog.LevelInfo,
}))
err := godotenv.Load(".env")
if err != nil {
log.Printf("warning: assuming default configuration. .env unreadable: %v", err)
Expand Down Expand Up @@ -89,10 +95,11 @@ func main() {

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

log.Printf("Serving on port: %s\n", port)
logger.Info(fmt.Sprintf("Serving on port: %s\n", port))
log.Fatal(srv.ListenAndServe())
}