Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PORT="8080"
Binary file added .github/.DS_Store
Binary file not shown.
48 changes: 48 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Deploy to Cloud Run

on:
push:
branches: [main]

jobs:
deploy:
name: Deploy
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: Build production app
run: ./scripts/buildprod.sh

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}

- name: Set up gcloud
uses: google-github-actions/setup-gcloud@v2
with:
project_id: industrial-joy-473515-v9

- name: Configure Docker for Artifact Registry
run: |
gcloud auth configure-docker us-central1-docker.pkg.dev

- name: Build and Push Docker image
run: |
gcloud builds submit --tag us-central1-docker.pkg.dev/industrial-joy-473515-v9/notely-ar-repo/notely:latest .

- name: Deploy to Cloud Run
run: |
gcloud run deploy notely-service \
--image us-central1-docker.pkg.dev/industrial-joy-473515-v9/notely-ar-repo/notely:latest \
--region us-central1 \
--platform managed \
--allow-unauthenticated
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: 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 ./...
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,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!

Fortune's version of Boot.dev's Notely app.
Binary file added bootdev
Binary file not shown.
Empty file added ci
Empty file.
Binary file added go/.DS_Store
Binary file not shown.
Binary file added go/bin/bootdev
Binary file not shown.
Binary file added go/bin/gopls
Binary file not shown.
Binary file added go/bin/staticcheck
Binary file not shown.
Binary file added internal/.DS_Store
Binary file not shown.
47 changes: 47 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package auth

import (
"net/http"
"testing"
)

// TestGetAPIKey tests the GetAPIKey function.
func TestGetAPIKey(t *testing.T) {
// Sub-test for a valid, well-formed Authorization header.
t.Run("Valid API Key", func(t *testing.T) {
headers := http.Header{}
headers.Set("Authorization", "ApiKey my-secret-key")

key, err := GetAPIKey(headers)
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
if key != "my-secret-key" {
t.Errorf("expected key to be 'my-secret-key', got '%s'", key)
}
})

// Sub-test for a missing Authorization header.
t.Run("No Auth Header", func(t *testing.T) {
headers := http.Header{}

_, err := GetAPIKey(headers)
if err == nil {
t.Fatal("expected an error, but got none")
}
if err != ErrNoAuthHeaderIncluded {
t.Errorf("expected error '%v', got '%v'", ErrNoAuthHeaderIncluded, err)
}
})

// Sub-test for a malformed Authorization header.
t.Run("Malformed Auth Header", func(t *testing.T) {
headers := http.Header{}
headers.Set("Authorization", "Bearer some-other-token")

_, err := GetAPIKey(headers)
if err == nil {
t.Fatal("expected an error, but got none")
}
})
}
Binary file added sql/.DS_Store
Binary file not shown.
Binary file added vendor/.DS_Store
Binary file not shown.