Skip to content
Open

merge #1791

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
dc09cac
changes
ahsan0098 Jul 13, 2025
c06e675
yml file added
ahsan0098 Aug 3, 2025
79b30b1
checking cicd working
ahsan0098 Aug 3, 2025
480e8c4
Merge branch 'addtests' of https://github.com/ahsan0098/learn-cicd-st…
ahsan0098 Aug 3, 2025
17ddf18
checking cicd working
ahsan0098 Aug 3, 2025
4b6d0fd
ci failure test
ahsan0098 Aug 6, 2025
f5a9a27
testing
ahsan0098 Aug 6, 2025
88ad2d4
Fix CI to run go tests
ahsan0098 Aug 6, 2025
8e05b50
Fix CI to run go tests
ahsan0098 Aug 6, 2025
9c96d63
fixing ci
ahsan0098 Aug 6, 2025
9a8d54e
dd
ahsan0098 Aug 6, 2025
2ed5080
sdfsd
ahsan0098 Aug 6, 2025
abd20bc
dfsf
ahsan0098 Aug 6, 2025
bb9119a
..
ahsan0098 Aug 7, 2025
6ad7792
..
ahsan0098 Aug 7, 2025
c9724c4
..
ahsan0098 Aug 7, 2025
3a224a3
..
ahsan0098 Aug 7, 2025
1a5d4e2
..
ahsan0098 Aug 7, 2025
33d6c98
..
ahsan0098 Aug 7, 2025
c3d2c39
..
ahsan0098 Aug 7, 2025
9a3b55b
..
ahsan0098 Aug 7, 2025
6352efb
added style test
ahsan0098 Aug 7, 2025
69113cf
added style test
ahsan0098 Aug 7, 2025
a4ae117
added cover flag to tests
ahsan0098 Aug 7, 2025
03f5c97
added failing liniting test
ahsan0098 Aug 7, 2025
5daef25
fixed failing liniting test
ahsan0098 Aug 7, 2025
90f4f63
added successing liniting test
ahsan0098 Aug 7, 2025
cd98c63
added successing liniting test
ahsan0098 Aug 7, 2025
6b7701e
formating
ahsan0098 Aug 7, 2025
54bc80e
Merge pull request #2 from ahsan0098/addtests
ahsan0098 Sep 2, 2025
dd33cf7
added gosec test
ahsan0098 Sep 2, 2025
c1ecb74
added gosec test 2
ahsan0098 Sep 2, 2025
5be443b
added gosec test 3
ahsan0098 Sep 2, 2025
2802cc0
added gosec test...locally passed...ci check
ahsan0098 Sep 2, 2025
09437c2
added gosec test...locally passed...ci checked...styling issue fixed
ahsan0098 Sep 2, 2025
6ae91c9
Merge branch 'addtests'
ahsan0098 Sep 2, 2025
c1748e9
Merge pull request #3 from ahsan0098/addtests
ahsan0098 Sep 2, 2025
2eb732c
deployement : cd.yml created...testing setup
ahsan0098 Sep 2, 2025
8c9fca6
Merge branch 'main' of https://github.com/ahsan0098/learn-cicd-starter
ahsan0098 Sep 2, 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
22 changes: 22 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: cd

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

- name: Build the app
run: scripts/buildprod.sh
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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 unit tests
run: go test ./... -cover

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: Formatting check
run: test -z "$(go fmt ./...)"

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

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

security:
name: Security
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: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest

- name: Run staticcheck linter
run: gosec ./...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
out
.env
learn-cicd-starter
notely.exe
notely
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# learn-cicd-starter (Notely)


![alt text goes here](https://github.com/ahsan0098/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)
This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev).

## Local Development
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!

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

func TestSomething(t *testing.T) {
t.Log("go test")
}
7 changes: 6 additions & 1 deletion json.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ 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 JSON: %s", err)
w.WriteHeader(500)
return
}
}
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