MCPcopy
hub / github.com/olric-data/olric / loadServiceDiscoveryPlugin

Method loadServiceDiscoveryPlugin

internal/discovery/discovery.go:95–132  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

93}
94
95func (d *Discovery) loadServiceDiscoveryPlugin() error {
96 var sd service_discovery.ServiceDiscovery
97
98 if val, ok := d.config.ServiceDiscovery["plugin"]; ok {
99 if sd, ok = val.(service_discovery.ServiceDiscovery); !ok {
100 return fmt.Errorf("plugin type %T is not a ServiceDiscovery interface", val)
101 }
102 } else {
103 pluginPath, ok := d.config.ServiceDiscovery["path"]
104 if !ok {
105 return fmt.Errorf("plugin path could not be found")
106 }
107 plug, err := plugin.Open(pluginPath.(string))
108 if err != nil {
109 return fmt.Errorf("failed to open plugin: %w", err)
110 }
111
112 symDiscovery, err := plug.Lookup("ServiceDiscovery")
113 if err != nil {
114 return fmt.Errorf("failed to lookup serviceDiscovery symbol: %w", err)
115 }
116
117 if sd, ok = symDiscovery.(service_discovery.ServiceDiscovery); !ok {
118 return fmt.Errorf("unable to assert type to serviceDiscovery")
119 }
120 }
121
122 if err := sd.SetConfig(d.config.ServiceDiscovery); err != nil {
123 return err
124 }
125 sd.SetLogger(d.config.Logger)
126 if err := sd.Initialize(); err != nil {
127 return err
128 }
129
130 d.serviceDiscovery = sd
131 return nil
132}
133
134// increaseUptimeSeconds calls UptimeSeconds.Increase function every second.
135func (d *Discovery) increaseUptimeSeconds() {

Callers 1

StartMethod · 0.95

Calls 3

SetConfigMethod · 0.95
SetLoggerMethod · 0.95
InitializeMethod · 0.95

Tested by

no test coverage detected