1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 18:37:05 +00:00

add accesslog+MVC example

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-09-17 18:01:35 +03:00
parent 0c125baf2a
commit 7fa2666f58
4 changed files with 46 additions and 15 deletions

View File

@@ -159,6 +159,16 @@ func sessionHandler(ctx iris.Context) {
ctx.WriteString("OK")
}
type user struct {
ID string
Username string
}
// Log custom structs, they can implement the fmt.Stringer interface too.
func (u user) String() string {
return u.ID + ":" + u.Username
}
func fieldsHandler(ctx iris.Context) {
start := time.Now()
// simulate a heavy job...
@@ -169,5 +179,13 @@ func fieldsHandler(ctx iris.Context) {
logFields := accesslog.GetFields(ctx)
logFields.Set("job_latency", end.Round(time.Second))
// Simulate a database fetch or anything
// to get a "user" and log it:
u := user{
ID: "user-id",
Username: "user-name",
}
logFields.Set("user", u)
ctx.WriteString("OK")
}