mirror of
https://github.com/tarampampam/error-pages.git
synced 2024-08-30 18:22:40 +00:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
d40e8879d1 | |||
6a67510bdc | |||
a79521a37d | |||
4667194271 | |||
a20852b03a | |||
ec0f1cc0d3 | |||
49d9650d35 | |||
1b876c45cc | |||
23f52f25e2 | |||
16d7d80183 | |||
5389fe00dd | |||
cd67674976 | |||
36673a49a4 |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -35,7 +35,7 @@ jobs:
|
||||
|
||||
- name: Generate builder values
|
||||
id: values
|
||||
run: echo "::set-output name=binary-name::error-pages-${{ matrix.os }}-${{ matrix.arch }}"
|
||||
run: echo "binary-name=error-pages-${{ matrix.os }}-${{ matrix.arch }}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build application
|
||||
env:
|
||||
|
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@ -192,7 +192,7 @@ jobs: # Docs: <https://git.io/JvxXE>
|
||||
name: docker-image
|
||||
path: .artifact
|
||||
|
||||
- uses: aquasecurity/trivy-action@0.8.0 # action page: <https://github.com/aquasecurity/trivy-action>
|
||||
- uses: aquasecurity/trivy-action@0.9.2 # action page: <https://github.com/aquasecurity/trivy-action>
|
||||
with:
|
||||
input: .artifact/docker-image.tar
|
||||
format: sarif
|
||||
|
@ -4,6 +4,14 @@ All notable changes to this package will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].
|
||||
|
||||
## v2.22.0
|
||||
|
||||
### Changed
|
||||
|
||||
- Non-existing pages now return styled `404` status page (with `404` status code) [#188]
|
||||
|
||||
[#188]:https://github.com/tarampampam/error-pages/issues/188
|
||||
|
||||
## v2.21.0
|
||||
|
||||
### Changed
|
||||
|
@ -33,7 +33,7 @@ services:
|
||||
retries: 5
|
||||
|
||||
golint:
|
||||
image: golangci/golangci-lint:v1.51-alpine # Image page: <https://hub.docker.com/r/golangci/golangci-lint>
|
||||
image: golangci/golangci-lint:v1.52-alpine # Image page: <https://hub.docker.com/r/golangci/golangci-lint>
|
||||
environment:
|
||||
GOLANGCI_LINT_CACHE: /tmp/golint # <https://github.com/golangci/golangci-lint/blob/v1.42.0/internal/cache/default.go#L68>
|
||||
volumes:
|
||||
|
18
go.mod
18
go.mod
@ -4,17 +4,17 @@ go 1.20
|
||||
|
||||
require (
|
||||
github.com/a8m/envsubst v1.4.2
|
||||
github.com/fasthttp/router v1.4.16
|
||||
github.com/fatih/color v1.14.1
|
||||
github.com/fasthttp/router v1.4.18
|
||||
github.com/fatih/color v1.15.0
|
||||
github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/prometheus/client_golang v1.14.0
|
||||
github.com/prometheus/client_model v0.3.0
|
||||
github.com/stretchr/testify v1.8.1
|
||||
github.com/urfave/cli/v2 v2.24.4
|
||||
github.com/valyala/fasthttp v1.44.0
|
||||
go.uber.org/automaxprocs v1.5.1
|
||||
go.uber.org/goleak v1.2.0
|
||||
github.com/stretchr/testify v1.8.2
|
||||
github.com/urfave/cli/v2 v2.25.1
|
||||
github.com/valyala/fasthttp v1.45.0
|
||||
go.uber.org/automaxprocs v1.5.2
|
||||
go.uber.org/goleak v1.2.1
|
||||
go.uber.org/zap v1.24.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
@ -27,7 +27,7 @@ require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.15.15 // indirect
|
||||
github.com/klauspost/compress v1.16.3 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
@ -43,6 +43,6 @@ require (
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
golang.org/x/sys v0.6.0 // indirect
|
||||
google.golang.org/protobuf v1.28.1 // indirect
|
||||
)
|
||||
|
55
go.sum
55
go.sum
@ -1,6 +1,5 @@
|
||||
github.com/a8m/envsubst v1.4.2 h1:4yWIHXOLEJHQEFd4UjrWDrYeYlV7ncFWJOCBRLOZHQg=
|
||||
github.com/a8m/envsubst v1.4.2/go.mod h1:MVUTQNGQ3tsjOOtKCNd+fl8RzhsXcDvvAEzkhGtlsbY=
|
||||
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
@ -14,10 +13,10 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fasthttp/router v1.4.16 h1:faWJ9OtaHvAtodreyQLps58M80YFNzphMJtOJzeESXs=
|
||||
github.com/fasthttp/router v1.4.16/go.mod h1:NFNlTCilbRVkeLc+E5JDkcxUdkpiJGKDL8Zy7Ey2JTI=
|
||||
github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
|
||||
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
|
||||
github.com/fasthttp/router v1.4.18 h1:elMnlFq527oZd8MHsuUpO6uLDup1exv8rXPfIjClDHk=
|
||||
github.com/fasthttp/router v1.4.18/go.mod h1:ZmC20Mn0VgCBbUWFDmnYzFbQYRfdGeKgpkBy0+JioKA=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
@ -26,14 +25,12 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
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/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d h1:cVtBfNW5XTHiKQe7jDaDBSh/EVM4XLPutLAGboIXuM0=
|
||||
github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d/go.mod h1:P2viExyCEfeWGU259JnaQ34Inuec4R38JCyBx2edgD0=
|
||||
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
|
||||
github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw=
|
||||
github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4=
|
||||
github.com/klauspost/compress v1.16.3 h1:XuJt9zzcnaz6a16/OU53ZjWp/v7/42WcR5t2a0PcNQY=
|
||||
github.com/klauspost/compress v1.16.3/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
@ -64,7 +61,6 @@ github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJf
|
||||
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4=
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk=
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
@ -73,45 +69,30 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/urfave/cli/v2 v2.24.4 h1:0gyJJEBYtCV87zI/x2nZCPyDxD51K6xM8SkwjHFCNEU=
|
||||
github.com/urfave/cli/v2 v2.24.4/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/urfave/cli/v2 v2.25.1 h1:zw8dSP7ghX0Gmm8vugrs6q9Ku0wzweqPyshy+syu9Gw=
|
||||
github.com/urfave/cli/v2 v2.25.1/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.44.0 h1:R+gLUhldIsfg1HokMuQjdQ5bh9nuXHPIfvkYUu9eR5Q=
|
||||
github.com/valyala/fasthttp v1.44.0/go.mod h1:f6VbjjoI3z1NDOZOv17o6RvtRSWxC77seBFc2uWtgiY=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
github.com/valyala/fasthttp v1.45.0 h1:zPkkzpIn8tdHZUrVa6PzYd0i5verqiPSkgTd3bSUcpA=
|
||||
github.com/valyala/fasthttp v1.45.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
|
||||
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||
go.uber.org/automaxprocs v1.5.1 h1:e1YG66Lrk73dn4qhg8WFSvhF0JuFQF0ERIp4rpuV8Qk=
|
||||
go.uber.org/automaxprocs v1.5.1/go.mod h1:BF4eumQw0P9GtnuxxovUd06vwm1o18oMzFtK66vU6XU=
|
||||
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
|
||||
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
|
||||
go.uber.org/automaxprocs v1.5.2 h1:2LxUOGiR3O6tw8ui5sZa2LAaHnsviZdVOUZw4fvbnME=
|
||||
go.uber.org/automaxprocs v1.5.2/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
|
||||
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
|
||||
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
|
||||
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
||||
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
|
||||
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
|
||||
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
|
||||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
|
@ -1,220 +0,0 @@
|
||||
package serve
|
||||
|
||||
// import (
|
||||
// "fmt"
|
||||
// "net"
|
||||
// "sort"
|
||||
// "strconv"
|
||||
// "strings"
|
||||
//
|
||||
// "github.com/spf13/pflag"
|
||||
//
|
||||
// "gh.tarampamp.am/error-pages/internal/env"
|
||||
// "gh.tarampamp.am/error-pages/internal/options"
|
||||
// )
|
||||
//
|
||||
// type flags struct {
|
||||
// Listen struct {
|
||||
// IP string
|
||||
// Port uint16
|
||||
// }
|
||||
// template struct {
|
||||
// name string
|
||||
// }
|
||||
// l10n struct {
|
||||
// disabled bool
|
||||
// }
|
||||
// defaultErrorPage string
|
||||
// defaultHTTPCode uint16
|
||||
// showDetails bool
|
||||
// proxyHTTPHeaders string // comma-separated
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// func (f *flags) Init(flagSet *pflag.FlagSet) {
|
||||
// flagSet.StringVarP(
|
||||
// &f.Listen.IP,
|
||||
// listenFlagName, "l",
|
||||
// "0.0.0.0",
|
||||
// fmt.Sprintf("IP address to Listen on [$%s]", env.ListenAddr),
|
||||
// )
|
||||
// flagSet.Uint16VarP(
|
||||
// &f.Listen.Port,
|
||||
// portFlagName, "p",
|
||||
// 8080, //nolint:gomnd // must be same as default healthcheck `--port` flag value
|
||||
// fmt.Sprintf("TCP prt number [$%s]", env.ListenPort),
|
||||
// )
|
||||
// flagSet.StringVarP(
|
||||
// &f.template.name,
|
||||
// templateNameFlagName, "t",
|
||||
// "",
|
||||
// fmt.Sprintf(
|
||||
// "template name (set \"%s\" to use a randomized or \"%s\" to use a randomized template on each request "+
|
||||
// "or \"%s/%s\" daily/hourly randomized) [$%s]",
|
||||
// useRandomTemplate,
|
||||
// useRandomTemplateOnEachRequest,
|
||||
// useRandomTemplateDaily,
|
||||
// useRandomTemplateHourly,
|
||||
// env.TemplateName,
|
||||
// ),
|
||||
// )
|
||||
// flagSet.StringVarP(
|
||||
// &f.defaultErrorPage,
|
||||
// defaultErrorPageFlagName, "",
|
||||
// "404",
|
||||
// fmt.Sprintf("default error page [$%s]", env.DefaultErrorPage),
|
||||
// )
|
||||
// flagSet.Uint16VarP(
|
||||
// &f.defaultHTTPCode,
|
||||
// defaultHTTPCodeFlagName, "",
|
||||
// 404, //nolint:gomnd
|
||||
// fmt.Sprintf("default HTTP response code [$%s]", env.DefaultHTTPCode),
|
||||
// )
|
||||
// flagSet.BoolVarP(
|
||||
// &f.showDetails,
|
||||
// showDetailsFlagName, "",
|
||||
// false,
|
||||
// fmt.Sprintf("show request details in response [$%s]", env.ShowDetails),
|
||||
// )
|
||||
// flagSet.StringVarP(
|
||||
// &f.proxyHTTPHeaders,
|
||||
// proxyHTTPHeadersFlagName, "",
|
||||
// "",
|
||||
// fmt.Sprintf("proxy HTTP request headers list (comma-separated) [$%s]", env.ProxyHTTPHeaders),
|
||||
// )
|
||||
// flagSet.BoolVarP(
|
||||
// &f.l10n.disabled,
|
||||
// disableL10nFlagName, "",
|
||||
// false,
|
||||
// fmt.Sprintf("disable error pages localization [$%s]", env.DisableL10n),
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// func (f *flags) OverrideUsingEnv(flagSet *pflag.FlagSet) (lastErr error) { //nolint:gocognit,gocyclo
|
||||
// flagSet.VisitAll(func(flag *pflag.Flag) {
|
||||
// // flag was NOT defined using CLI (flags should have maximal priority)
|
||||
// if !flag.Changed { //nolint:nestif
|
||||
// switch flag.Name {
|
||||
// case listenFlagName:
|
||||
// if envVar, exists := env.ListenAddr.Lookup(); exists {
|
||||
// f.Listen.IP = strings.TrimSpace(envVar)
|
||||
// }
|
||||
//
|
||||
// case portFlagName:
|
||||
// if envVar, exists := env.ListenPort.Lookup(); exists {
|
||||
// if p, err := strconv.ParseUint(envVar, 10, 16); err == nil {
|
||||
// f.Listen.Port = uint16(p)
|
||||
// } else {
|
||||
// lastErr = fmt.Errorf("wrong TCP port environment variable [%s] value", envVar)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// case templateNameFlagName:
|
||||
// if envVar, exists := env.TemplateName.Lookup(); exists {
|
||||
// f.template.name = strings.TrimSpace(envVar)
|
||||
// }
|
||||
//
|
||||
// case defaultErrorPageFlagName:
|
||||
// if envVar, exists := env.DefaultErrorPage.Lookup(); exists {
|
||||
// f.defaultErrorPage = strings.TrimSpace(envVar)
|
||||
// }
|
||||
//
|
||||
// case defaultHTTPCodeFlagName:
|
||||
// if envVar, exists := env.DefaultHTTPCode.Lookup(); exists {
|
||||
// if code, err := strconv.ParseUint(envVar, 10, 16); err == nil {
|
||||
// f.defaultHTTPCode = uint16(code)
|
||||
// } else {
|
||||
// lastErr = fmt.Errorf("wrong default HTTP response code environment variable [%s] value", envVar)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// case showDetailsFlagName:
|
||||
// if envVar, exists := env.ShowDetails.Lookup(); exists {
|
||||
// if b, err := strconv.ParseBool(envVar); err == nil {
|
||||
// f.showDetails = b
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// case proxyHTTPHeadersFlagName:
|
||||
// if envVar, exists := env.ProxyHTTPHeaders.Lookup(); exists {
|
||||
// f.proxyHTTPHeaders = strings.TrimSpace(envVar)
|
||||
// }
|
||||
//
|
||||
// case disableL10nFlagName:
|
||||
// if envVar, exists := env.DisableL10n.Lookup(); exists {
|
||||
// if b, err := strconv.ParseBool(envVar); err == nil {
|
||||
// f.l10n.disabled = b
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// return lastErr
|
||||
// }
|
||||
//
|
||||
// func (f *flags) Validate() error {
|
||||
// if net.ParseIP(f.Listen.IP) == nil {
|
||||
// return fmt.Errorf("wrong IP address [%s] for listening", f.Listen.IP)
|
||||
// }
|
||||
//
|
||||
// if f.defaultHTTPCode > 599 { //nolint:gomnd
|
||||
// return fmt.Errorf("wrong default HTTP response code [%d]", f.defaultHTTPCode)
|
||||
// }
|
||||
//
|
||||
// if strings.ContainsRune(f.proxyHTTPHeaders, ' ') {
|
||||
// return fmt.Errorf("whitespaces in the HTTP headers for proxying [%s] are not allowed", f.proxyHTTPHeaders)
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// // headersToProxy converts a comma-separated string with headers list into strings slice (with a sorting and without
|
||||
// // duplicates).
|
||||
// func (f *flags) headersToProxy() []string {
|
||||
// var raw = strings.Split(f.proxyHTTPHeaders, ",")
|
||||
//
|
||||
// if len(raw) == 0 {
|
||||
// return []string{}
|
||||
// } else if len(raw) == 1 {
|
||||
// if h := strings.TrimSpace(raw[0]); h != "" {
|
||||
// return []string{h}
|
||||
// } else {
|
||||
// return []string{}
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// var m = make(map[string]struct{}, len(raw))
|
||||
//
|
||||
// // make unique and ignore empty strings
|
||||
// for _, h := range raw {
|
||||
// if h = strings.TrimSpace(h); h != "" {
|
||||
// if _, ok := m[h]; !ok {
|
||||
// m[h] = struct{}{}
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // convert map into slice
|
||||
// var headers = make([]string, 0, len(m))
|
||||
// for h := range m {
|
||||
// headers = append(headers, h)
|
||||
// }
|
||||
//
|
||||
// // make sort
|
||||
// sort.Strings(headers)
|
||||
//
|
||||
// return headers
|
||||
// }
|
||||
//
|
||||
// func (f *flags) ToOptions() (o options.ErrorPage) {
|
||||
// o.Default.PageCode = f.defaultErrorPage
|
||||
// o.Default.HTTPCode = f.defaultHTTPCode
|
||||
// o.L10n.Disabled = f.l10n.disabled
|
||||
// o.Template.Name = f.template.name
|
||||
// o.ShowDetails = f.showDetails
|
||||
// o.ProxyHTTPHeaders = f.headersToProxy()
|
||||
//
|
||||
// return o
|
||||
// }
|
@ -2,13 +2,27 @@ package notfound
|
||||
|
||||
import (
|
||||
"github.com/valyala/fasthttp"
|
||||
|
||||
"gh.tarampamp.am/error-pages/internal/config"
|
||||
"gh.tarampamp.am/error-pages/internal/http/core"
|
||||
"gh.tarampamp.am/error-pages/internal/options"
|
||||
"gh.tarampamp.am/error-pages/internal/tpl"
|
||||
)
|
||||
|
||||
type (
|
||||
templatePicker interface {
|
||||
// Pick the template name for responding.
|
||||
Pick() string
|
||||
}
|
||||
|
||||
renderer interface {
|
||||
Render(content []byte, props tpl.Properties) ([]byte, error)
|
||||
}
|
||||
)
|
||||
|
||||
// NewHandler creates handler missing requests handling.
|
||||
func NewHandler() fasthttp.RequestHandler {
|
||||
func NewHandler(cfg *config.Config, p templatePicker, rdr renderer, opt options.ErrorPage) fasthttp.RequestHandler {
|
||||
return func(ctx *fasthttp.RequestCtx) {
|
||||
ctx.SetContentType("text/plain; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusNotFound)
|
||||
_, _ = ctx.WriteString("Wrong request URL. Error pages are available at the following URLs: /{code}.html")
|
||||
core.RespondWithErrorPage(ctx, cfg, p, rdr, "404", fasthttp.StatusNotFound, opt)
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ func (s *Server) Register(cfg *config.Config, templatePicker templatePicker, opt
|
||||
|
||||
s.router.GET("/metrics", metricsHandler.NewHandler(reg))
|
||||
|
||||
s.router.NotFound = notfoundHandler.NewHandler()
|
||||
s.router.NotFound = notfoundHandler.NewHandler(cfg, templatePicker, s.rdr, opt)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ GET http://{{ host }}:{{ port }}/not-found
|
||||
HTTP/* 404
|
||||
|
||||
[Asserts]
|
||||
header "Content-Type" contains "text/plain"
|
||||
body contains "Wrong request URL"
|
||||
header "Content-Type" contains "text/html"
|
||||
body contains "The server can not find the requested page"
|
||||
|
Reference in New Issue
Block a user