github.com/tobgu/qframe@v0.4.0/config/eval/config.go (about) 1 package eval 2 3 // Config holds configuration for evaluating expressions on QFrames. 4 // It should be considered a private implementation detail and should never be 5 // referenced or used directly outside of the QFrame code. To manipulate it 6 // use the functions returning ConfigFunc below. 7 type Config struct { 8 Ctx *Context 9 } 10 11 // ConfigFunc is a function that operates on a Config object. 12 type ConfigFunc func(*Config) 13 14 // NewConfig creates a new Config object. 15 // This function should never be called from outside QFrame. 16 func NewConfig(ff []ConfigFunc) Config { 17 result := Config{} 18 for _, f := range ff { 19 f(&result) 20 } 21 22 if result.Ctx == nil { 23 result.Ctx = NewDefaultCtx() 24 } 25 26 return result 27 } 28 29 // EvalContext sets the evaluation context to use. 30 func EvalContext(ctx *Context) ConfigFunc { 31 return func(c *Config) { 32 c.Ctx = ctx 33 } 34 }