Skip to content

Commit

Permalink
Merge pull request #11 from voi-go/make-must-init-smooter
Browse files Browse the repository at this point in the history
Make MustInit smoother
  • Loading branch information
drPytho authored Dec 4, 2019
2 parents 6a092dc + 252bd34 commit 7cf64c0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,15 @@ func (s *SVC) Shutdown() {
}

// MustInit is a convenience function to check for and halt on errors.
func MustInit(s *SVC, err error) {
func MustInit(s *SVC, err error) *SVC {
if err != nil {
if s == nil || s.logger == nil {
panic(err)
}
s.logger.Fatal("Service initialization failed", zap.Error(err), zap.Stack("stacktrace"))
return nil
}
return s
}

// Logger returns the service's logger. Logger might be nil if New() fails.
Expand Down

0 comments on commit 7cf64c0

Please sign in to comment.