generated from clevergo/pkg-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanager.go
37 lines (31 loc) · 829 Bytes
/
manager.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
28
29
30
31
32
33
34
35
36
37
// Copyright 2020 CleverGo. All rights reserved.
// Use of this source code is governed by a MIT style license that can be found
// in the LICENSE file.
package plugins
import (
"path"
"plugin"
)
// Manager is a manager that manage plugins.
type Manager struct {
// The location of plugins.
Path string
}
// New returns a plugins manager with the given path.
func New(path string) *Manager {
return &Manager{
Path: path,
}
}
// Open opens a Go plugin.
func (pm *Manager) Open(name string) (*plugin.Plugin, error) {
return plugin.Open(path.Join(pm.Path, name))
}
// Lookup searches for a symbol named symName in a plugin named pluginName.
func (pm *Manager) Lookup(pluginName, symName string) (plugin.Symbol, error) {
p, err := pm.Open(pluginName)
if err != nil {
return nil, err
}
return p.Lookup(symName)
}