delaunay/mst working
This commit is contained in:
45
util/appctx/context.go
Normal file
45
util/appctx/context.go
Normal file
@ -0,0 +1,45 @@
|
||||
package appctx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"lab.zaar.be/thefish/alchemyst-go/util"
|
||||
)
|
||||
|
||||
const (
|
||||
configKey = "config"
|
||||
loggerKey = "logger"
|
||||
)
|
||||
|
||||
type ClientCtx struct {
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func NewClientContext(config *util.Config, logger *zerolog.Logger) ClientCtx {
|
||||
ctx := context.Context(context.TODO())
|
||||
ctx = context.WithValue(ctx, configKey, config)
|
||||
ctx = context.WithValue(ctx, loggerKey, logger)
|
||||
return ClientCtx{ctx: ctx}
|
||||
}
|
||||
|
||||
func (c *ClientCtx) Config() *util.Config {
|
||||
cfg, ok := c.ctx.Value(configKey).(*util.Config)
|
||||
if !ok {
|
||||
panic(fmt.Errorf("no access to config from context"))
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (c *ClientCtx) Logger() *zerolog.Logger {
|
||||
logger, ok := c.ctx.Value(loggerKey).(*zerolog.Logger)
|
||||
if !ok {
|
||||
panic(fmt.Errorf("no access to logger from context"))
|
||||
}
|
||||
return logger
|
||||
}
|
||||
|
||||
//func FromContext(appctx context.Context) (*User, bool) {
|
||||
// u, ok := appctx.Value(userKey).(*User)
|
||||
// return u, ok
|
||||
//}
|
Reference in New Issue
Block a user