Skip to content

Commit

Permalink
Merge pull request #27 from hatena/use-stdlib
Browse files Browse the repository at this point in the history
log/slogを使う
  • Loading branch information
ne-sachirou authored Mar 26, 2024
2 parents acea902 + a07f1ba commit ff80895
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/task-test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- uses: golangci/golangci-lint-action@v4
with:
skip-pkg-cache: true # https://github.com/golangci/golangci-lint-action/issues/677
Expand All @@ -24,5 +26,7 @@ jobs:
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: test
run: make test-go
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module github.com/hatena/chi-middlewares

go 1.20
go 1.22

toolchain go1.22.1

require (
github.com/go-chi/chi/v5 v5.0.12
github.com/google/go-cmp v0.6.0
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s=
github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 h1:6R2FC06FonbXQ8pK11/PDFY6N6LWlf9KlzibaCapmqc=
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ=
2 changes: 1 addition & 1 deletion logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package logger

import (
"context"
"log/slog"
"net/http"

"github.com/go-chi/chi/v5/middleware"
"golang.org/x/exp/slog"
)

type LogKey struct{}
Expand Down
2 changes: 1 addition & 1 deletion logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"io"
"log/slog"
"math/rand"
"net/http"
"net/http/httptest"
Expand All @@ -13,7 +14,6 @@ import (

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"golang.org/x/exp/slog"
)

func Test_Logger(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions logger/request_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package logger
import (
"context"
"fmt"
"log/slog"
"net/http"
"time"

"github.com/go-chi/chi/v5/middleware"
"golang.org/x/exp/slog"
)

// RequestLogger は、HTTP request が完了した時にその要約を log に吐く。Logger は RequestLogger の前に置かねばならない。middleware.RealIP は RequestLogger の前に置かねばならない。middleware.Recoverer は RequestLogger の後に置かねばならない
Expand Down Expand Up @@ -64,7 +64,7 @@ func (e *requestLogEntry) Write(

// middleware.Recoverer が呼ぶ
func (e *requestLogEntry) Panic(v interface{}, stack []byte) {
e.log.ErrorCtx(
e.log.ErrorContext(
e.ctx,
"panic",
slog.String("panic", fmt.Sprintf("%+v", v)),
Expand Down
2 changes: 1 addition & 1 deletion logger/request_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"log/slog"
"math/rand"
"net/http"
"net/http/httptest"
Expand All @@ -13,7 +14,6 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/google/go-cmp/cmp"
"golang.org/x/exp/slog"
)

func Test_RequestLogger(t *testing.T) {
Expand Down

0 comments on commit ff80895

Please sign in to comment.