feat: split path into 2 variables (path+route)
This commit is contained in:
@@ -2,8 +2,6 @@ name: Lint
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
|
||||||
branches:
|
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -17,28 +15,6 @@ jobs:
|
|||||||
stable: false
|
stable: false
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v2
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
args: --timeout 120s --max-same-issues 50
|
||||||
version: latest
|
|
||||||
|
|
||||||
# Optional: working directory, useful for monorepos
|
|
||||||
working-directory: ./
|
|
||||||
|
|
||||||
# Optional: golangci-lint command line arguments.
|
|
||||||
args: --timeout 60s --max-same-issues 50
|
|
||||||
|
|
||||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
|
||||||
# only-new-issues: true
|
|
||||||
|
|
||||||
# Optional: if set to true then the action will use pre-installed Go.
|
|
||||||
# skip-go-installation: true
|
|
||||||
|
|
||||||
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
|
|
||||||
# skip-pkg-cache: true
|
|
||||||
|
|
||||||
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
|
|
||||||
# skip-build-cache: true
|
|
||||||
|
|
||||||
# optionally use a specific version of Go rather than the latest one
|
|
||||||
go_version: '1.21'
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ router.GET("/pong", func(c *gin.Context) {
|
|||||||
router.Run(":1234")
|
router.Run(":1234")
|
||||||
|
|
||||||
// output:
|
// output:
|
||||||
// time=2023-04-10T14:00:0.000000Z level=INFO msg="Incoming request" status=200 method=GET path=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time=2023-04-10T14:00:00.000Z
|
// time=2023-04-10T14:00:0.000000Z level=INFO msg="Incoming request" status=200 method=GET path=/pong route=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time=2023-04-10T14:00:00.000Z
|
||||||
```
|
```
|
||||||
|
|
||||||
### Filters
|
### Filters
|
||||||
@@ -158,7 +158,7 @@ router.GET("/pong", func(c *gin.Context) {
|
|||||||
router.Run(":1234")
|
router.Run(":1234")
|
||||||
|
|
||||||
// output:
|
// output:
|
||||||
// time="2023-04-10 14:00:00" level=INFO msg="Incoming request" status=200 method=GET path=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time="2023-04-10 14:00:00"
|
// time="2023-04-10 14:00:00" level=INFO msg="Incoming request" status=200 method=GET path=/pong route=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time="2023-04-10 14:00:00"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Using custom logger sub-group
|
### Using custom logger sub-group
|
||||||
@@ -188,7 +188,7 @@ router.GET("/pong", func(c *gin.Context) {
|
|||||||
router.Run(":1234")
|
router.Run(":1234")
|
||||||
|
|
||||||
// output:
|
// output:
|
||||||
// time=2023-04-10T14:00:0.000000+02:00 level=INFO msg="Incoming request" http.status=200 http.method=GET http.path=/pong http.ip=127.0.0.1 http.latency=20.125µs http.user-agent=curl/7.77.0 time=2023-04-10T14:00:00.000+02:00
|
// time=2023-04-10T14:00:0.000000+02:00 level=INFO msg="Incoming request" http.status=200 http.method=GET http.path=/pong http.route=/pong http.ip=127.0.0.1 http.latency=20.125µs http.user-agent=curl/7.77.0 time=2023-04-10T14:00:00.000+02:00
|
||||||
```
|
```
|
||||||
|
|
||||||
### Add logger to a single route
|
### Add logger to a single route
|
||||||
@@ -215,7 +215,7 @@ router.GET("/pong", sloggin.New(logger), func(c *gin.Context) {
|
|||||||
router.Run(":1234")
|
router.Run(":1234")
|
||||||
|
|
||||||
// output:
|
// output:
|
||||||
// time="2023-04-10 14:00:00" level=INFO msg="Incoming request" status=200 method=GET path=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time="2023-04-10 14:00:00"
|
// time="2023-04-10 14:00:00" level=INFO msg="Incoming request" status=200 method=GET path=/pong route=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time="2023-04-10 14:00:00"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Adding custom attributes
|
### Adding custom attributes
|
||||||
@@ -249,7 +249,7 @@ router.GET("/pong", func(c *gin.Context) {
|
|||||||
router.Run(":1234")
|
router.Run(":1234")
|
||||||
|
|
||||||
// output:
|
// output:
|
||||||
// time=2023-04-10T14:00:0.000000+02:00 level=INFO msg="Incoming request" environment=production server=gin/1.9.0 gin_mode=release server_start_time=2023-04-10T10:00:00.000+02:00 status=200 method=GET path=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time=2023-04-10T14:00:00.000+02:00
|
// time=2023-04-10T14:00:0.000000+02:00 level=INFO msg="Incoming request" environment=production server=gin/1.9.0 gin_mode=release server_start_time=2023-04-10T10:00:00.000+02:00 status=200 method=GET path=/pong route=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time=2023-04-10T14:00:00.000+02:00
|
||||||
```
|
```
|
||||||
|
|
||||||
### JSON output
|
### JSON output
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ func main() {
|
|||||||
router.GET("/pong", func(c *gin.Context) {
|
router.GET("/pong", func(c *gin.Context) {
|
||||||
c.String(http.StatusOK, "pong")
|
c.String(http.StatusOK, "pong")
|
||||||
})
|
})
|
||||||
|
router.GET("/pong/:id", func(c *gin.Context) {
|
||||||
|
c.String(http.StatusOK, "pong")
|
||||||
|
})
|
||||||
|
|
||||||
logger.Info("Starting server")
|
logger.Info("Starting server")
|
||||||
if err := router.Run(":1234"); err != nil {
|
if err := router.Run(":1234"); err != nil {
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ func NewWithConfig(logger *slog.Logger, config Config) gin.HandlerFunc {
|
|||||||
slog.Int("status", c.Writer.Status()),
|
slog.Int("status", c.Writer.Status()),
|
||||||
slog.String("method", c.Request.Method),
|
slog.String("method", c.Request.Method),
|
||||||
slog.String("path", path),
|
slog.String("path", path),
|
||||||
|
slog.String("route", c.FullPath()),
|
||||||
slog.String("ip", c.ClientIP()),
|
slog.String("ip", c.ClientIP()),
|
||||||
slog.Duration("latency", latency),
|
slog.Duration("latency", latency),
|
||||||
slog.String("user-agent", c.Request.UserAgent()),
|
slog.String("user-agent", c.Request.UserAgent()),
|
||||||
|
|||||||
Reference in New Issue
Block a user