go-age | An age calculator for Golang | Apps library
kandi X-RAY | go-age Summary
kandi X-RAY | go-age Summary
Go-Age
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- AgeAt returns the number of years since the given birthday date .
- getAdjustedBirthDay calculates the adjusted birthday day based on the current time .
- isLeap reports whether date is a leap date .
- Age returns the age of the given model .
go-age Key Features
go-age Examples and Code Snippets
Community Discussions
Trending Discussions on go-age
QUESTION
I am creating new relic transaction in main.go and have to pass it along to handler and then to controller and so on. Is there a way i can define this globally and then can be accessed in any handler, controller or and db transaction?
...ANSWER
Answered 2021-Oct-17 at 07:08Avoid using a global context, rather create one at the entrypoint and then just pass it as an argument to any function that needs it.
You can make use of the nrgin
package provided by the Gin framework.
And in the main()
function
- Create an instance of newrelic -
newrelic.NewApplication(cfg)
- Call the -
nrgin.Middleware(app)
function passing in the newrelic instance. This will add the Gin transaction context key -newRelicTransaction
to the context. - Register the function in step 2 as a middleware for all your routes -
router.Use(nrgin.Middleware(app))
You can then pass this same context object to your other functions that can accept a parameter of type context.Context
since gin.Context
is simply implementing the context
interface of Go.
Example code
QUESTION
I am using the gin-gonic, newrelic go-agent v3, and nrgin v3
I am trying to figure out how to propagate a custom error message from a Handler so that it shows up in New Relic.
What I see now is that when I have a handler that returns with a http.StatusInternalServerError, the error message shows up in New Relic as "500: Internal Server Error".
I'd like to figure out how to have that be suffixed with the message in the error being thrown.
Here's what I'm doing now, and it's clearly not working:
...ANSWER
Answered 2021-May-13 at 19:02I think you have to set the error on the transaction manually.
The nrgin
middleware doesn't do anything after c.Next
, which is where you would typically inspect errors, however it does set the newrelic.Transaction
into the Gin context:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install go-age
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page