-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.go
27 lines (22 loc) · 910 Bytes
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package goarc
// Service represents a generic service that goarc framework can Start and Stop.
type Service interface {
// Start should initiate the startup of the service.
// It returns an error if the startup process encounters any issues.
Start() error
// Stop should initiate the shutdown of the service.
// It returns an error if the shutdown process encounters any issues.
Stop() error
}
// ServiceFunc serves as an adapter, enabling the utilization of regular functions as goarc services.
// If f is a function with the correct signature, ServiceFunc(f) creates a Service that invokes f.
// The function f receives a boolean parameter indicating whether it's invoked as Start (true) or Stop (false).
type ServiceFunc func(bool) error
// Start calls f(true).
func (s ServiceFunc) Start() error {
return s(true)
}
// Stop calls f(false).
func (s ServiceFunc) Stop() error {
return s(false)
}