Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib/gin-gonic/gin: ensure build for <v1.4.0 versions too #593

Merged
merged 3 commits into from
Feb 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion contrib/gin-gonic/gin/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package gin

import (
"math"
"net/http"

"github.com/gin-gonic/gin"
"gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig"
Expand Down Expand Up @@ -59,5 +60,15 @@ func WithResourceNamer(namer func(c *gin.Context) string) Option {
}

func defaultResourceNamer(c *gin.Context) string {
return c.Request.Method + " " + c.FullPath()
// getName is a hacky way to check whether *gin.Context implements the FullPath()
// method introduced in v1.4.0, falling back to the previous implementation otherwise.
getName := func(req *http.Request, c interface{ HandlerName() string }) string {
if fp, ok := c.(interface {
FullPath() string
}); ok {
return req.Method + " " + fp.FullPath()
}
return c.HandlerName()
}
return getName(c.Request, c)
}