Skip to content

Commit

Permalink
Update library and add more comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
KaKa Lee committed Mar 23, 2017
1 parent cf84085 commit 23d693f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 5 additions & 4 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import:
- package: github.com/satori/go.uuid
version: ^1.1.0
- package: go.uber.org/zap
version: ^1.0.0-rc.2
version: ^1.0.0
subpackages:
- zapcore
testImport:
Expand Down
6 changes: 4 additions & 2 deletions lg.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ func L(ctx context.Context) *zap.Logger {
// LogRequest to log every request.
func LogRequest(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
// Add a requestID field to logger
l := log.With(zap.String("requestID", uuid.NewV1().String()))
ctx := r.Context()
ctx = context.WithValue(ctx, requestIDKey, l)
// Add logger to context
ctx := context.WithValue(r.Context(), requestIDKey, l)
// Request with this new context.
r = r.WithContext(ctx)

// Start timer
Expand Down

0 comments on commit 23d693f

Please sign in to comment.