delphi.market/server/router/context/context.go

39 lines
969 B
Go
Raw Normal View History

package context
import (
2024-07-09 20:41:29 +00:00
"context"
"git.ekzyis.com/ekzyis/delphi.market/db"
"git.ekzyis.com/ekzyis/delphi.market/lnd"
"github.com/labstack/echo/v4"
)
2024-07-09 20:41:29 +00:00
type Context struct {
context.Context
Environment string
PublicURL string
CommitShortSha string
CommitLongSha string
Version string
Db *db.DB
Lnd *lnd.LNDClient
}
2024-07-09 20:41:29 +00:00
type RenderContextKey string
var (
EnvContextKey RenderContextKey = "env"
SessionContextKey RenderContextKey = "session"
CommitContextKey RenderContextKey = "commit"
2024-07-12 11:26:27 +00:00
ReqPathContextKey RenderContextKey = "reqPath"
2024-07-09 20:41:29 +00:00
)
2024-07-09 20:41:29 +00:00
func RenderContext(sc Context, c echo.Context) context.Context {
ctx := c.Request().Context()
ctx = context.WithValue(ctx, EnvContextKey, sc.Environment)
ctx = context.WithValue(ctx, SessionContextKey, c.Get("session"))
ctx = context.WithValue(ctx, CommitContextKey, sc.CommitShortSha)
2024-07-12 11:26:27 +00:00
ctx = context.WithValue(ctx, ReqPathContextKey, c.Request().URL.Path)
2024-07-09 20:41:29 +00:00
return ctx
}