From 57aa11607045f78e747c6d1e1da878d43a0e7146 Mon Sep 17 00:00:00 2001 From: Daniel Theophanes Date: Sat, 2 Mar 2013 22:41:57 -0800 Subject: [PATCH] Make Init able to be aborted. --- stdservice/stdservice.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/stdservice/stdservice.go b/stdservice/stdservice.go index 29639a5..321a8f9 100644 --- a/stdservice/stdservice.go +++ b/stdservice/stdservice.go @@ -13,12 +13,14 @@ type Config struct { Name, DisplayName, LongDescription string // Called when the service starts or stops. - // Stop() may be nil. + // Stop may be nil. Start, Stop func(c *Config) // Called after logging may be setup but before the service is started. - // Init() is optional and may be nil. - Init func(c *Config) + // Init is optional and may be nil. + // If Init returns an error, that error is logged to the logger + // and the service start is aborted. + Init func(c *Config) error s service.Service l service.Logger @@ -92,7 +94,11 @@ func Run(c *Config) { } if c.Init != nil { - c.Init(c) + err := c.Init(c) + if err != nil { + c.l.Error(err.Error()) + return + } } err = s.Run(func() error {