github.com/Anderson-Lu/gobox@v0.0.0-20191127065433-3e6c4c2da420/application/application_demo.go (about) 1 package application 2 3 import "fmt" 4 5 type fContext struct { 6 } 7 8 //Init your custom context obj, such as db connections, log configs etc by implements ApplicationContext interface 9 func (self fContext) Init() { 10 11 } 12 13 func (self fContext) MyOwnMethod() { 14 15 } 16 17 func demo() { 18 context := fContext{} 19 context.Init() 20 fmt.Println("地址", &context) 21 app := NewApplication() 22 app.SetContext(&context) 23 app.SetOnStart(onStart) 24 app.SetOnStop(onStop) 25 app.Run(run) 26 } 27 28 func onStart(c *ApplicationContext) { 29 30 } 31 32 func onStop(c *ApplicationContext) { 33 fmt.Println("地址", &c) 34 } 35 36 func run(c *ApplicationContext) { 37 38 }