bfe
bfe copied to clipboard
design bfe program launch as service
bfe's entrance include many jobs to do, split them into different parts as below example. It'll take more scalabilities, like
- support callback when
Init
orStart
- register signal
syscall.SIGHUP
func as to do reload config - close logger when
Stop
etc.
reference from go-svc
type bfe struct {
}
// Init do initialize
func (b *bfe) Init(env svc.Environment) error {
flag.Parse()
if *help {
flag.PrintDefaults()
return nil
}
return nil
}
// Start do start
func (b *bfe) Start() error {
var err error
var config bfe_conf.BfeConfig
// start and serve
if err = bfe_server.StartUp(config, version, *confRoot); err != nil {
log.Logger.Error("main(): bfe_server.StartUp(): %s", err.Error())
return err
}
return nil
}
// Stop do stop
func (b *bfe) Stop() error {
return nil
}
func main() {
b := &bfe{}
if err := svc.Run(b, syscall.SIGINT, syscall.SIGTERM); err != nil {
bfe_util.AbnormalExit()
}
}