-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice_module.go
More file actions
36 lines (29 loc) · 1.03 KB
/
service_module.go
File metadata and controls
36 lines (29 loc) · 1.03 KB
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
28
29
30
31
32
33
34
35
36
package module
import "github.com/CrisisTextLine/modular"
// ServiceModule wraps any Go object as a modular.Module, registering it
// in the service registry under the given name. This allows delegate-based
// dispatch: a QueryHandler or CommandHandler can name a delegate service,
// and that service (if it implements http.Handler) handles the actual HTTP
// dispatch.
type ServiceModule struct {
name string
service any
}
// NewServiceModule creates a ServiceModule that registers svc under name.
func NewServiceModule(name string, svc any) *ServiceModule {
return &ServiceModule{name: name, service: svc}
}
func (m *ServiceModule) Name() string { return m.name }
func (m *ServiceModule) Init(_ modular.Application) error { return nil }
func (m *ServiceModule) ProvidesServices() []modular.ServiceProvider {
return []modular.ServiceProvider{
{
Name: m.name,
Description: "Service delegate: " + m.name,
Instance: m.service,
},
}
}
func (m *ServiceModule) RequiresServices() []modular.ServiceDependency {
return nil
}