1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-30 05:55:20 -05:00

prototype for plugins

This commit is contained in:
Darien Raymond
2017-11-22 23:00:46 +01:00
parent bfafd06863
commit 6069b77baa
3 changed files with 73 additions and 0 deletions

53
plugin.go Normal file
View File

@@ -0,0 +1,53 @@
package core
import (
"os"
"path/filepath"
"plugin"
"strings"
"v2ray.com/core/app/log"
"v2ray.com/core/common/platform"
)
type PluginMetadata struct {
Name string
}
const GetMetadataFuncName = "GetPluginMetadata"
type GetMetadataFunc func() PluginMetadata
func LoadPlugins() error {
pluginPath := platform.GetPluginDirectory()
dir, err := os.Open(pluginPath)
if err != nil {
return err
}
defer dir.Close()
files, err := dir.Readdir(-1)
if err != nil {
return err
}
for _, file := range files {
if !file.IsDir() && strings.HasSuffix(file.Name(), ".so") {
p, err := plugin.Open(filepath.Join(pluginPath, file.Name()))
if err != nil {
return err
}
f, err := p.Lookup(GetMetadataFuncName)
if err != nil {
return err
}
if gmf, ok := f.(GetMetadataFunc); ok {
metadata := gmf()
log.Trace(newError("plugin (", metadata.Name, ") loaded."))
}
}
}
return nil
}