Giter Site home page Giter Site logo

chizap's Introduction

chizap

😄 chizap

go.dev reference License GitHub release Docker Metrics Made by Manfred Touron

Go Release PR GolangCI codecov Go Report Card CodeFactor

Gitpod ready-to-code

Example

import (
	"github.com/go-chi/chi"
	"go.uber.org/zap"
	"moul.io/chizap"
)

func Example() {
	logger := zap.NewExample()
	r := chi.NewRouter()
	r.Use(chizap.New(logger, &chizap.Opts{
		WithReferer:   true,
		WithUserAgent: true,
	}))
}

Usage

FUNCTIONS

func New(logger *zap.Logger, opts *Opts) func(next http.Handler) http.Handler
    New returns a logger middleware for chi, that implements the http.Handler
    interface.


TYPES

type Opts struct {
	// WithReferer enables logging the "Referer" HTTP header value.
	WithReferer bool

	// WithUserAgent enables logging the "User-Agent" HTTP header value.
	WithUserAgent bool
}
    Opts contains the middleware configuration.

Install

Using go

go get moul.io/chizap

Releases

See https://github.com/moul/chizap/releases

Contribute

Contribute <3

I really welcome contributions. Your input is the most precious material. I'm well aware of that and I thank you in advance. Everyone is encouraged to look at what they can do on their own scale; no effort is too small.

Everything on contribution is sum up here: CONTRIBUTING.md

Dev helpers

Pre-commit script for install: https://pre-commit.com

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):


Manfred Touron

🚧 📖 ⚠️ 💻

moul-bot

🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

Stargazers over time

Stargazers over time

License

© 2021 Manfred Touron

Licensed under the Apache License, Version 2.0 (LICENSE-APACHE) or the MIT license (LICENSE-MIT), at your option. See the COPYRIGHT file for more details.

SPDX-License-Identifier: (Apache-2.0 OR MIT)

chizap's People

Contributors

dependabot[bot] avatar moul avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

simonmacklin

chizap's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/codeql-analysis.yml
  • actions/checkout v3.0.2
  • github/codeql-action v2
  • github/codeql-action v2
  • github/codeql-action v2
.github/workflows/debug.yml
.github/workflows/go.yml
  • actions/checkout v3.0.2
  • moul/repoman-action v1
  • actions/checkout v3.0.2
  • actions/setup-go v3
  • actions/cache v3.0.7
  • goreleaser/goreleaser-action v2.8.0
  • actions/checkout v3.0.2
  • golangci/golangci-lint-action v3
  • actions/checkout v3.0.2
  • actions/setup-go v3
  • actions/checkout v3.0.2
  • actions/setup-go v3
  • actions/cache v3.0.7
  • codecov/codecov-action v3
  • actions/checkout v3.0.2
  • actions/setup-go v3
  • actions/cache v3.0.7
  • codecov/codecov-action v3
.github/workflows/pr.yml
  • actions/checkout v3.0.2
  • snyk/release-notes-preview v1.6.2
  • actions/checkout v3.0.2
.github/workflows/release.yml
  • actions/checkout v3.0.2
  • moul/repoman-action v1
  • ghcr.io/codfish/semantic-release-action v1
  • actions/setup-go v3
  • actions/cache v3.0.7
  • goreleaser/goreleaser-action v2.8.0
gomod
go.mod
  • go 1.13
  • github.com/go-chi/chi v1.5.4
  • github.com/stretchr/testify v1.8.0
  • github.com/tailscale/depaware v0.0.0-20210622194025-720c4b409502@720c4b409502
  • go.uber.org/zap v1.19.1
npm
package.json
tool/lint/package.json
  • alex 9.1.0
  • markdown-spellcheck 1.3.1
  • markdownlint-cli 0.27.1
  • remark-cli 10.0.1
  • remark-lint 9.1.1

  • Check this box to trigger a request for Renovate to run again on this repository

[BUG] Request ID is empty with go-chi imported with major version suffix

Describe the bug
chizap can't properly get the request id value from the context due to working with another major version of go-chi

To Reproduce
Steps to reproduce the behavior:

  1. Install go-chi with major version suffix like /v5 (github.com/go-chi/chi/v5)
  2. Build and run small example below
package main

import (
	"fmt"
	"net/http"

	"github.com/go-chi/chi/v5"
	"github.com/go-chi/chi/v5/middleware"
	"go.uber.org/zap"
	"moul.io/chizap"
)

func main() {
	logger, _ := zap.NewProduction()

	r := chi.NewRouter()
	r.Use(middleware.RequestID)
	r.Use(chizap.New(logger, &chizap.Opts{
		WithReferer:   true,
		WithUserAgent: true,
	}))

	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Request ID: %s", middleware.GetReqID(r.Context()))
	})

	http.ListenAndServe(":3000", r)
}

Expected behavior
The request id should be presented in logs

Versions (please complete the following information, if relevant):

  • Software version: the latest
  • OS: macOS
  • Golang version 1.19.5

Additional context
I'm new in Go and idk how to contribute to your project, but I maybe know why it doesn't work. Each version of go-chi creates its own type (link to src). My project works on chi/v5 and writes the value to the context by own RequestIDKey. When chizap tries to read the value from the same context it attempts to read the value by RequestIDKey from chi version v1.5.4 (according to your go.mod). It doesn't exist and logs contain the empty request id.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.