magicwallet/server/router/context/context.go

28 lines
695 B
Go

package context
import (
"context"
"github.com/ekzyis/magicwallet/db"
"github.com/ekzyis/magicwallet/lightning"
"github.com/labstack/echo/v4"
)
type Context struct {
context.Context
Environment string
CommitShortSha string
Db *db.DB
Lnd *lightning.LNDClient
}
func (hc *Context) WithContext(ec echo.Context) context.Context {
ctx := ec.Request().Context()
ctx = context.WithValue(ctx, "env", hc.Environment)
ctx = context.WithValue(ctx, "commit", hc.CommitShortSha)
ctx = context.WithValue(ctx, "path", ec.Request().URL.Path)
ctx = context.WithValue(ctx, "user", ec.Get("user"))
ctx = context.WithValue(ctx, "wallet", ec.Get("wallet"))
return ctx
}