Comments (3)
Hi @savsgio Thank you for you answer
edit: sorry for my stupid statement. after thinking about it, it's not possible to get the transfer time. because only client knows that. Thank you, it works perfectly
this isn't not included the transfer time right? only the execution time.
because it's not even close to the time on my browser
from atreugo.
Hi @iDevoid,
If you want to know all registered paths in atreugo, you could call to ListPaths.
So if you need the requested path, method and the time execution, you must defined a middleware in main router (not in groups) at first of all to register all information in request and other at last to print or doing anything with these information:
package main
import (
"fmt"
"github.com/savsgio/atreugo/v10"
"time"
)
func main() {
config := &atreugo.Config{
Addr: "0.0.0.0:8000",
}
server := atreugo.New(config)
type HandlerInfo struct {
method []byte
path []byte
tsStart int64
}
// The first middleware
server.UseBefore(func(ctx *atreugo.RequestCtx) error {
ctx.SetUserValue("info", HandlerInfo{
method: ctx.Method(),
path: ctx.Path(),
tsStart: time.Now().UnixNano(),
})
return ctx.Next()
})
// The last middleware
server.UseAfter(func(ctx *atreugo.RequestCtx) error {
info := ctx.UserValue("info").(HandlerInfo)
timeHandler := time.Now().UnixNano() - info.tsStart
fmt.Printf("Method: %s \nPath: %s \nTime handler: %d nanosecs\n", info.method, info.path, timeHandler)
return ctx.Next()
})
// Register a route
server.Path("GET", "/", func(ctx *atreugo.RequestCtx) error {
return ctx.TextResponse("Hello World")
})
err := server.ListenAndServe()
if err != nil {
panic(err)
}
}
from atreugo.
Don't worry.
Anything else, I will be here!
from atreugo.
Related Issues (20)
- Possible breaking change in patch version? "path must begin with '/' in path ''" HOT 2
- AttachContext overrides previous AttachContext HOT 2
- Hi, Savsgio, how to add CORS middleware? HOT 30
- Is it possible to run "after" middleware even when "before" middleware exits error? HOT 5
- Unable to match URL with "/" ending HOT 1
- Unsupported path parameters with root / prefix HOT 1
- Problem with trailing "/" when optional url param is empty (11 version) - 308 redirect HOT 3
- I can not install HOT 1
- Error! installing with go get github.com/savsgio/atreugo HOT 5
- Cannot update/download deps HOT 1
- any sort of html template kind of real life example code to go with? router with html hello world at least HOT 1
- Instrumenting servers / paths to add metrics doesn't work when view returns an error HOT 1
- Use atreugo and autocert HOT 2
- Support custom logger HOT 4
- Possible race condition in context propagation HOT 3
- rate limit middleware request HOT 3
- Race condition when calling RequestCtx.Value() HOT 4
- Sentry APM Middleware HOT 1
- Occasional panic HOT 1
- Configurable JSON Marshaller HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from atreugo.