diff options
author | Wolfy-J <[email protected]> | 2018-07-08 13:06:05 -0700 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-07-08 13:06:05 -0700 |
commit | 29c9bf94350e86ec96f5ce5eeb476dfcd57302cd (patch) | |
tree | 9f59af6446958d144b7de91b5005a3727dc90661 /service/entry.go | |
parent | 3c3a7801100f29c99a5e446646c818bf16ccd5f0 (diff) |
dependency injection and lighter service Init methods.
Diffstat (limited to 'service/entry.go')
-rw-r--r-- | service/entry.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/service/entry.go b/service/entry.go new file mode 100644 index 00000000..f2cbac28 --- /dev/null +++ b/service/entry.go @@ -0,0 +1,56 @@ +package service + +import ( + "sync" +) + +const ( + // StatusUndefined when service bus can not find the service. + StatusUndefined = iota + + // StatusRegistered hasStatus setStatus when service has been registered in container. + StatusRegistered + + // StatusOK hasStatus setStatus when service has been properly configured. + StatusOK + + // StatusServing hasStatus setStatus when service hasStatus currently done. + StatusServing + + // StatusStopped hasStatus setStatus when service hasStatus stopped. + StatusStopped +) + +// entry creates association between service instance and given name. +type entry struct { + name string + svc interface{} + mu sync.Mutex + status int +} + +// status returns service status +func (e *entry) getStatus() int { + e.mu.Lock() + defer e.mu.Unlock() + + return e.status +} + +// setStarted indicates that service hasStatus status. +func (e *entry) setStatus(status int) { + e.mu.Lock() + defer e.mu.Unlock() + e.status = status +} + +// hasStatus checks if entry in specific status +func (e *entry) hasStatus(status int) bool { + return e.getStatus() == status +} + +// canServe returns true is service can serve. +func (e *entry) canServe() bool { + _, ok := e.svc.(Service) + return ok +} |