Compare commits

..

6 Commits

Author SHA1 Message Date
Renovate 1ac6787016 chore(deps): update module go to 1.19
continuous-integration/drone/pr Build is passing Details
2022-12-11 16:00:16 +00:00
Dawid Wysokiński 89b13247b1
chore: update README.md
continuous-integration/drone/push Build is passing Details
2022-12-11 10:15:17 +01:00
renovate 2432b5bcab chore(deps): update module github.com/go-chi/chi/v5 to v5.0.8 (#10)
continuous-integration/drone/push Build is passing Details
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/go-chi/chi/v5](https://github.com/go-chi/chi) | require | patch | `v5.0.7` -> `v5.0.8` |

---

### Release Notes

<details>
<summary>go-chi/chi</summary>

### [`v5.0.8`](https://github.com/go-chi/chi/blob/HEAD/CHANGELOG.md#v508-2022-12-07)

[Compare Source](https://github.com/go-chi/chi/compare/v5.0.7...v5.0.8)

-   History of changes: see https://github.com/go-chi/chi/compare/v5.0.7...v5.0.8

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yMy4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjMuMCJ9-->

Co-authored-by: Renovate <renovate@dwysokinski.me>
Reviewed-on: #10
Co-authored-by: renovate <renovate@noreply.localhost>
Co-committed-by: renovate <renovate@noreply.localhost>
2022-12-11 08:02:29 +00:00
renovate bd9657b489 chore(deps): update module github.com/stretchr/testify to v1.8.1 (#8)
continuous-integration/drone/push Build is passing Details
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/stretchr/testify](https://github.com/stretchr/testify) | require | patch | `v1.8.0` -> `v1.8.1` |

---

### Release Notes

<details>
<summary>stretchr/testify</summary>

### [`v1.8.1`](https://github.com/stretchr/testify/compare/v1.8.0...v1.8.1)

[Compare Source](https://github.com/stretchr/testify/compare/v1.8.0...v1.8.1)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4yMjQuMCIsInVwZGF0ZWRJblZlciI6IjM0LjIzLjAifQ==-->

Co-authored-by: Renovate <renovate@dwysokinski.me>
Reviewed-on: #8
Co-authored-by: renovate <renovate@noreply.localhost>
Co-committed-by: renovate <renovate@noreply.localhost>
2022-12-01 08:18:26 +00:00
renovate 8f902152b1 chore(deps): update module go.uber.org/zap to v1.24.0 (#9)
continuous-integration/drone/push Build is passing Details
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [go.uber.org/zap](https://github.com/uber-go/zap) | require | minor | `v1.23.0` -> `v1.24.0` |

---

### Release Notes

<details>
<summary>uber-go/zap</summary>

### [`v1.24.0`](https://github.com/uber-go/zap/releases/tag/v1.24.0)

[Compare Source](https://github.com/uber-go/zap/compare/v1.23.0...v1.24.0)

Enhancements:

-   [#&#8203;1148][]: Add `Level` to both `Logger` and `SugaredLogger` that reports the
    current minimum enabled log level.
-   [#&#8203;1185][]: `SugaredLogger` turns errors to zap.Error automatically.

Thanks to [@&#8203;Abirdcfly](https://github.com/Abirdcfly), [@&#8203;craigpastro](https://github.com/craigpastro), [@&#8203;nnnkkk7](https://github.com/nnnkkk7), and [@&#8203;sashamelentyev](https://github.com/sashamelentyev) for their
contributions to this release.

[#&#8203;1148]: https://github.com/uber-go/zap/pull/1148

[#&#8203;1185]: https://github.com/uber-go/zap/pull/1185

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yMy4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjMuMCJ9-->

Co-authored-by: Renovate <renovate@dwysokinski.me>
Reviewed-on: #9
Co-authored-by: renovate <renovate@noreply.localhost>
Co-committed-by: renovate <renovate@noreply.localhost>
2022-12-01 04:27:28 +00:00
Dawid Wysokiński 0bbf45fb93
update README.md
continuous-integration/drone/push Build is passing Details
2022-10-12 15:14:09 +02:00
6 changed files with 94 additions and 122 deletions

View File

@ -1,13 +1,92 @@
# chizap [![Build Status](https://drone.dwysokinski.me/api/badges/Kichiyaki/chizap/status.svg?ref=refs/heads/master)](https://drone.dwysokinski.me/Kichiyaki/chizap)
Request logging middleware for [go-chi](https://github.com/go-chi/chi) using [zap](https://github.com/uber-go/zap).
A request logging middleware for [go-chi](https://github.com/go-chi/chi) using [zap](https://github.com/uber-go/zap).
## Installation
## Getting started
```bash
### Installation
```shell
go get gitea.dwysokinski.me/Kichiyaki/chizap
```
## Usage
### Usage
See the [example](./_example/basic/main.go).
```go
package main
import (
"log"
"net/http"
"strings"
"time"
"gitea.dwysokinski.me/Kichiyaki/chizap"
"github.com/go-chi/chi/v5"
"go.uber.org/zap"
)
func main() {
logger, err := zap.NewDevelopment()
if err != nil {
log.Fatalln("zap.NewDevelopment", err)
}
http.ListenAndServe(":8080", newRouter(logger))
}
func newRouter(logger *zap.Logger) *chi.Mux {
router := chi.NewRouter()
router.Route("/", func(r chi.Router) {
r.Use(chizap.Logger(
logger,
chizap.WithFilter(func(r *http.Request) bool {
return r.URL.Path != "/excluded"
}),
chizap.WithFilter(func(r *http.Request) bool {
return r.URL.Path != "/excluded2"
}),
chizap.WithAdditionalFieldExtractor(func(r *http.Request) []zap.Field {
if !strings.HasPrefix(r.URL.Path, "/delete") {
return nil
}
return []zap.Field{
zap.String("id", chi.URLParam(r, "id")),
}
}),
))
r.Get("/info", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
r.Get("/warn", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
})
r.Get("/error", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
})
r.Get("/excluded", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
r.Delete("/delete/{id}", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
})
router.With(chizap.Logger(logger, chizap.WithTimeFormat(time.RFC1123Z))).
Get("/custom-time-format", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
return router
}
```
## License
Distributed under the MIT License. See ``LICENSE`` for more information.
## Contact
Dawid Wysokiński - [contact@dwysokinski.me](mailto:contact@dwysokinski.me)

View File

@ -1,16 +0,0 @@
module gitea.dwysokinski.me/Kichiyaki/chizap/_examples/basic
go 1.19
replace gitea.dwysokinski.me/Kichiyaki/chizap => ../..
require (
gitea.dwysokinski.me/Kichiyaki/chizap v0.2.1
github.com/go-chi/chi/v5 v5.0.7
go.uber.org/zap v1.23.0
)
require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
)

View File

@ -1,25 +0,0 @@
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
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/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY=
go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

View File

@ -1,68 +0,0 @@
package main
import (
"log"
"net/http"
"strings"
"time"
"gitea.dwysokinski.me/Kichiyaki/chizap"
"github.com/go-chi/chi/v5"
"go.uber.org/zap"
)
func main() {
logger, err := zap.NewDevelopment()
if err != nil {
log.Fatalln("zap.NewDevelopment", err)
}
http.ListenAndServe(":8080", newRouter(logger))
}
func newRouter(logger *zap.Logger) *chi.Mux {
router := chi.NewRouter()
router.Route("/", func(r chi.Router) {
r.Use(chizap.Logger(
logger,
chizap.WithFilter(func(r *http.Request) bool {
return r.URL.Path != "/excluded"
}),
chizap.WithFilter(func(r *http.Request) bool {
return r.URL.Path != "/excluded2"
}),
chizap.WithAdditionalFieldExtractor(func(r *http.Request) []zap.Field {
if !strings.HasPrefix(r.URL.Path, "/delete") {
return nil
}
return []zap.Field{
zap.String("id", chi.URLParam(r, "id")),
}
}),
))
r.Get("/info", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
r.Get("/warn", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
})
r.Get("/error", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
})
r.Get("/excluded", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
r.Delete("/delete/{id}", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
})
router.With(chizap.Logger(logger, chizap.WithTimeFormat(time.RFC1123Z))).
Get("/custom-time-format", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
return router
}

6
go.mod
View File

@ -3,9 +3,9 @@ module gitea.dwysokinski.me/Kichiyaki/chizap
go 1.19
require (
github.com/go-chi/chi/v5 v5.0.7
github.com/stretchr/testify v1.8.0
go.uber.org/zap v1.23.0
github.com/go-chi/chi/v5 v5.0.8
github.com/stretchr/testify v1.8.1
go.uber.org/zap v1.24.0
)
require (

12
go.sum
View File

@ -2,26 +2,28 @@ github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLj
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/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0=
github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
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=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY=
go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=