Skip to content

added name #1439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
62c5d8b
added my name to end of README
WarrenPaschetto Apr 25, 2025
bd37139
added name to end of README
WarrenPaschetto Apr 25, 2025
46d588e
Merge pull request #1 from WarrenPaschetto/addtests
WarrenPaschetto Apr 25, 2025
41289b4
added name to end of README
WarrenPaschetto Apr 25, 2025
0045dd8
Merge pull request #2 from WarrenPaschetto/addtests
WarrenPaschetto Apr 25, 2025
fca1ba1
added .github/workflows/ci.yml
WarrenPaschetto Apr 25, 2025
ebab0d4
changed last job in ci.yml to run go version
WarrenPaschetto Apr 25, 2025
0774d89
Merge pull request #3 from WarrenPaschetto/addtests
WarrenPaschetto Apr 25, 2025
d46cef3
added testing
WarrenPaschetto Apr 28, 2025
2ba380b
added testing
WarrenPaschetto Apr 28, 2025
a2957c0
Merge pull request #4 from WarrenPaschetto/addtests
WarrenPaschetto Apr 28, 2025
337365b
added test coverage to CI workflow
WarrenPaschetto Apr 28, 2025
455dd1f
Merge pull request #5 from WarrenPaschetto/addtests
WarrenPaschetto Apr 28, 2025
28c8082
added workflow badge to README
WarrenPaschetto Apr 28, 2025
87a6ddd
Merge pull request #6 from WarrenPaschetto/addtests
WarrenPaschetto Apr 28, 2025
193a4bc
added style to CI workflow jobs
WarrenPaschetto Apr 28, 2025
7a81d28
Merge pull request #7 from WarrenPaschetto/addtests
WarrenPaschetto Apr 28, 2025
9a12034
revised CI workflow jobs
WarrenPaschetto Apr 28, 2025
b11ad46
Merge pull request #8 from WarrenPaschetto/addtests
WarrenPaschetto Apr 28, 2025
abe8e23
added staticcheck to workflow
WarrenPaschetto Apr 28, 2025
4a61076
updated main
WarrenPaschetto Apr 28, 2025
a357ff5
updated main
WarrenPaschetto Apr 28, 2025
bd8bd29
updated main
WarrenPaschetto Apr 28, 2025
82a0977
updated main
WarrenPaschetto Apr 28, 2025
1c8ea7d
Merge pull request #9 from WarrenPaschetto/addtests
WarrenPaschetto Apr 28, 2025
d8652a8
added CI security with gosec to workflow
WarrenPaschetto Apr 29, 2025
295408c
fixed gosec errors
WarrenPaschetto Apr 29, 2025
da41272
Merge pull request #10 from WarrenPaschetto/addtests
WarrenPaschetto Apr 29, 2025
3c5ade9
added continuous deployment
WarrenPaschetto Apr 29, 2025
cc09bf7
Merge pull request #11 from WarrenPaschetto/addtests
WarrenPaschetto Apr 29, 2025
002946c
automate builds
WarrenPaschetto Apr 30, 2025
ca001ee
Merge pull request #12 from WarrenPaschetto/addtests
WarrenPaschetto Apr 30, 2025
e0428f0
edit <h1> and add deploy to Cloud Run in CD workflow
WarrenPaschetto Apr 30, 2025
62797ad
Merge pull request #13 from WarrenPaschetto/addtests
WarrenPaschetto Apr 30, 2025
97bf91e
edit <h1> and add deploy to Cloud Run in CD workflow
WarrenPaschetto Apr 30, 2025
6d7fc68
Merge pull request #14 from WarrenPaschetto/addtests
WarrenPaschetto Apr 30, 2025
e0d54fe
add goose migrations to CD workflow
WarrenPaschetto Apr 30, 2025
46bc93b
Merge pull request #15 from WarrenPaschetto/addtests
WarrenPaschetto Apr 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
47 changes: 47 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Deployment
on:
push:
branches: [main]

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
timeout-minutes: 30
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}

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

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

- name: Build app
run: ./scripts/buildprod.sh

- id: auth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2

- name: Use gcloud CLI
run: gcloud info

- name: Build and push Docker image
run: gcloud builds submit --tag us-central1-docker.pkg.dev/notely-458315/notely-ar-repo/wdpaschetto/notely:latest .

- name: Install goose
run: go install github.com/pressly/goose/v3/cmd/goose@latest

- name: Run migrations
run: ./scripts/migrateup.sh

- name: Deploy to Cloud Run
run: gcloud run deploy notely --image us-central1-docker.pkg.dev/notely-458315/notely-ar-repo/wdpaschetto/notely:latest --region us-central1 --allow-unauthenticated --project notely-458315 --max-instances=4
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.23.0"

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

- 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 ./...
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![alt dynamic badge for workflow tests](https://github.com/WarrenPaschetto/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 +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!

Warren Paschetto's version of Boot.dev's Notely app
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/E
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand All @@ -37,6 +39,7 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw=
github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4=
Expand All @@ -46,8 +49,10 @@ github.com/libsql/sqlite-antlr4-parser v0.0.0-20230802215326-5cb5bb604475 h1:6Pf
github.com/libsql/sqlite-antlr4-parser v0.0.0-20230802215326-5cb5bb604475/go.mod h1:20nXSmcf0nAscrzqsXeC2/tA3KkV2eCiJqYuyAgl+ss=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -64,14 +69,17 @@ golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfU
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g=
nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
62 changes: 62 additions & 0 deletions internal/auth/get_api_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package auth

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

func TestGetAPIKey(t *testing.T) {
tests := []struct {
key string
value string
expect string
expectErr string
}{
{
expectErr: "no authorization header",
},
{
key: "Authorization",
expectErr: "no authorization header",
},
{
key: "Authorization",
value: "-",
expectErr: "malformed authorization header",
},
{
key: "Authorization",
value: "Bearer xxxxxx",
expectErr: "malformed authorization header",
},
{
key: "Authorization",
value: "ApiKey xxxxxx",
expect: "xxxxxx",
expectErr: "not expecting an error",
},
}

for i, test := range tests {
t.Run(fmt.Sprintf("TestGetAPIKey Case #%v:", i), func(t *testing.T) {
header := http.Header{}
header.Add(test.key, test.value)

output, err := GetAPIKey(header)
if err != nil {
if strings.Contains(err.Error(), test.expectErr) {
return
}
t.Errorf("Unexpected: TestGetAPIKey:%v\n", err)
return
}

if output != test.expect {
t.Errorf("Unexpected: TestGetAPIKey:%s", output)
return
}
})
}
}
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.Printf("Error writing response: %s", 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
4 changes: 2 additions & 2 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>

<body class="section">
<h1>Notely</h1>
<h1>Welcome to Notely</h1>

<div id="userCreationContainer" class="section">
<input id="nameField" type="text" placeholder="Enter your name">
Expand Down Expand Up @@ -190,4 +190,4 @@ <h2>Your Notes</h2>
<!-- your existing CSS code... -->
</body>

</html>
</html>