Skip to content

Commit e811b40

Browse files
committed
chore: bump deps and clean code
1 parent 9814bb0 commit e811b40

File tree

10 files changed

+46
-122
lines changed

10 files changed

+46
-122
lines changed

.github/CODE_OF_CONDUCT.md

Lines changed: 0 additions & 76 deletions
This file was deleted.

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/cd.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v2
14+
uses: actions/checkout@v5
15+
with:
16+
fetch-depth: 0
1517
- name: Install Go
16-
uses: actions/setup-go@v2
18+
uses: actions/setup-go@v5
1719
with:
18-
go-version: '1.14'
19-
- name: Docker Hub Login
20-
run: docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
21-
env:
22-
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
23-
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
20+
go-version: stable
21+
- name: Login to Docker Hub
22+
uses: docker/login-action@v3
23+
with:
24+
username: ${{ secrets.DOCKER_USERNAME }}
25+
password: ${{ secrets.DOCKER_PASSWORD }}
2426
- name: Release
25-
uses: goreleaser/goreleaser-action@v1
27+
uses: goreleaser/goreleaser-action@v6
2628
with:
2729
version: latest
28-
args: release
30+
args: release --clean
2931
env:
3032
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/ci.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ on:
44
push:
55
pull_request:
66

7-
env:
8-
GO111MODULE: 'on'
9-
107
jobs:
118
lint:
129
name: Lint
1310
runs-on: ubuntu-latest
1411
steps:
1512
- name: Check out code
16-
uses: actions/checkout@master
17-
- name: Lint Go Code
18-
uses: docker://golangci/golangci-lint:latest
13+
uses: actions/checkout@v5
14+
- uses: actions/setup-go@v5
1915
with:
20-
args: golangci-lint run ./...
16+
go-version: stable
17+
- name: golangci-lint
18+
uses: golangci/golangci-lint-action@v8
2119
- name: Lint Helm Chart
2220
run: helm lint chart/uri-template-tester

.goreleaser.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
version: 2
12
before:
23
hooks:
34
- go mod download
@@ -10,30 +11,22 @@ builds:
1011
- darwin
1112
- windows
1213
goarch:
13-
- 386
14+
- "386"
1415
- amd64
1516
- arm
1617
- arm64
1718
archives:
1819
-
19-
replacements:
20-
darwin: Darwin
21-
linux: Linux
22-
windows: Windows
23-
386: i386
24-
amd64: x86_64
2520
files:
2621
- COPYRIGHT
2722
- LICENSE
2823
- README.md
2924
- public/*
3025
format_overrides:
3126
- goos: windows
32-
format: zip
27+
formats: [zip]
3328
checksum:
3429
name_template: 'checksums.txt'
35-
snapshot:
36-
name_template: "{{ .Tag }}-next"
3730
changelog:
3831
sort: asc
3932
filters:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ FROM gcr.io/distroless/static
22
COPY uri-template-tester /
33
COPY public /public/
44
CMD ["/uri-template-tester"]
5-
EXPOSE 80 443
5+
EXPOSE 80

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/dunglas/uri-template-tester
22

33
go 1.14
44

5-
require github.com/yosida95/uritemplate v0.0.0-20170413134207-5c22f358020b
5+
require github.com/yosida95/uritemplate v2.0.0+incompatible

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
github.com/yosida95/uritemplate v0.0.0-20170413134207-5c22f358020b h1:Lz1ji+ezbzsAY9OFYZxa+Tzao42+DMJIR6jn3N+H87I=
22
github.com/yosida95/uritemplate v0.0.0-20170413134207-5c22f358020b/go.mod h1:mksJanHNnLsh6wYgt/AbBRZ4ogsHsO2uiZlm/UURY5c=
3+
github.com/yosida95/uritemplate v2.0.0+incompatible h1:j6LR/+4tiD14zc0Z0M8QilHLULqgZFD47XqgXQgCE1A=
4+
github.com/yosida95/uritemplate v2.0.0+incompatible/go.mod h1:mksJanHNnLsh6wYgt/AbBRZ4ogsHsO2uiZlm/UURY5c=

main.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import (
55
"os"
66
)
77

8-
type error struct {
9-
Error string
10-
}
11-
128
func main() {
139
http.HandleFunc("/match", match)
1410
fs := http.FileServer(http.Dir("public"))

match.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6+
"log/slog"
67
"net/http"
78
"strings"
89

910
"github.com/yosida95/uritemplate"
1011
)
1112

13+
type jsonError struct {
14+
Error string
15+
}
16+
1217
func match(w http.ResponseWriter, r *http.Request) {
13-
w.Header().Set("Content-Type", "application/json")
18+
w.Header().Set("Content-Type", "application/payload")
1419
w.Header().Set("X-Content-Type-Options", "nosniff")
1520
w.Header().Set("X-Frame-Options", "deny")
1621

@@ -19,39 +24,44 @@ func match(w http.ResponseWriter, r *http.Request) {
1924

2025
errors := make([]string, 0, 2)
2126
if template == "" {
22-
errors = append(errors, "The \"template\" parameter is mandatory.")
27+
errors = append(errors, `The "template" parameter is mandatory.`)
2328
}
2429

2530
uri := query.Get("uri")
2631
if uri == "" {
27-
errors = append(errors, "The \"uri\" parameter is mandatory.")
32+
errors = append(errors, `The "uri" parameter is mandatory.`)
2833
}
2934

3035
if len(errors) > 0 {
31-
err, _ := json.MarshalIndent(error{strings.Join(errors, " ")}, "", " ")
32-
http.Error(w, string(err), http.StatusBadRequest)
36+
payload, _ := json.MarshalIndent(jsonError{strings.Join(errors, " ")}, "", " ")
37+
http.Error(w, string(payload), http.StatusBadRequest)
38+
3339
return
3440
}
3541

3642
tpl, err := uritemplate.New(template)
3743
if nil != err {
38-
err, _ := json.MarshalIndent(error{fmt.Sprintf("\"%s\" is not a valid URI template (RFC6570).", template)}, "", " ")
39-
http.Error(w, string(err), http.StatusBadRequest)
44+
payload, _ := json.MarshalIndent(jsonError{fmt.Sprintf(`"%s" is not a valid URI template (RFC6570).`, template)}, "", " ")
45+
http.Error(w, string(payload), http.StatusBadRequest)
46+
4047
return
4148
}
4249

4350
match := tpl.Match(uri)
4451
if match == nil {
45-
err, _ := json.Marshal(struct{ Match bool }{false})
46-
fmt.Fprintf(w, "%s", string(err))
52+
payload, _ := json.Marshal(struct{ Match bool }{false})
53+
if _, err := w.Write(payload); err != nil {
54+
slog.Info("failed to write response", "remote_addr", r.RemoteAddr, "error", err)
55+
}
56+
4757
return
4858
}
4959

50-
json, _ := json.MarshalIndent(struct {
60+
payload, _ := json.MarshalIndent(struct {
5161
Match bool
5262
Values uritemplate.Values
5363
}{true, match}, "", " ")
54-
if _, err := w.Write(json); err != nil {
55-
panic(err)
64+
if _, err := w.Write(payload); err != nil {
65+
slog.Info("failed to write response", "remote_addr", r.RemoteAddr, "error", err)
5666
}
5767
}

0 commit comments

Comments
 (0)