Skip to content

Commit 2c2c012

Browse files
committed
feat: catch all urls and not just /
1 parent 8951045 commit 2c2c012

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
ci: golang-ci
1+
ci: go-tests go-cover golang-ci
2+
3+
go-tests: src/* go.mod go.sum
4+
go test -v ./...
5+
6+
go-cover: src/* go.mod go.sum
7+
go test -coverprofile=coverage.out ./...
28

39
golang-ci: src/* go.mod go.sum
410
docker run --rm -t \

src/github.com/hoverkraft-tech/http-header-authenticator/main.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package main
22

33
import (
44
"fmt"
5+
"net/http"
6+
57
"github.com/gin-contrib/logger"
68
"github.com/gin-contrib/requestid"
79
"github.com/gin-gonic/gin"
810
"github.com/rs/zerolog"
911
"github.com/spf13/cobra"
10-
"net/http"
1112
)
1213

1314
func main() {
@@ -34,12 +35,18 @@ func main() {
3435
r.Use(requestid.New())
3536
r.Use(logger.SetLogger(l))
3637

37-
r.GET("/", func(c *gin.Context) {
38+
// Health check endpoint
39+
r.GET("/health", func(c *gin.Context) {
40+
c.String(http.StatusOK, "OK")
41+
})
42+
43+
// Check the presence of the header in all requests
44+
r.NoRoute(func(c *gin.Context) {
3845
value := c.GetHeader(headerName)
3946
if value == expectedValue {
4047
c.String(http.StatusOK, "HTTP header is present with the expected value.")
4148
} else {
42-
c.String(http.StatusNotFound, "HTTP header is not present with the expected value.")
49+
c.String(http.StatusForbidden, "HTTP header is not present with the expected value.")
4350
}
4451
})
4552

0 commit comments

Comments
 (0)