github.com/awesome-flow/flow@v0.0.3-0.20190918184116-508d75d68a2c/pkg/corev1alpha1/context.go (about) 1 package corev1alpha1 2 3 import ( 4 "os" 5 6 "github.com/awesome-flow/flow/pkg/util" 7 ) 8 9 type Context struct { 10 logger *Logger 11 config *Config 12 } 13 14 var _ Runner = (*Context)(nil) 15 16 func NewContext(config *Config) (*Context, error) { 17 logger, err := initLogger(config) 18 if err != nil { 19 return nil, err 20 } 21 return &Context{ 22 logger: logger, 23 config: config, 24 }, nil 25 } 26 27 func initLogger(config *Config) (*Logger, error) { 28 //TODO: configure logger 29 return NewLogger(os.Stdout), nil 30 } 31 32 func (ctx *Context) Start() error { 33 if err := util.ExecEnsure( 34 ctx.logger.Start, 35 ctx.config.Start, 36 ); err != nil { 37 return err 38 } 39 return nil 40 } 41 42 func (ctx *Context) Stop() error { 43 if err := util.ExecEnsure( 44 ctx.logger.Stop, 45 ctx.config.Stop, 46 ); err != nil { 47 return err 48 } 49 return nil 50 } 51 52 func (ctx *Context) Logger() *Logger { 53 return ctx.logger 54 } 55 56 func (ctx *Context) Config() *Config { 57 return ctx.config 58 }