1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

load plugin only in linux

This commit is contained in:
Darien Raymond 2017-11-22 23:11:32 +01:00
parent 6069b77baa
commit 9db6c187c6
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
3 changed files with 54 additions and 44 deletions

View File

@ -1,15 +1,5 @@
package core
import (
"os"
"path/filepath"
"plugin"
"strings"
"v2ray.com/core/app/log"
"v2ray.com/core/common/platform"
)
type PluginMetadata struct {
Name string
}
@ -17,37 +7,3 @@ type PluginMetadata struct {
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
}

47
plugin_linux.go Normal file
View File

@ -0,0 +1,47 @@
// +build linux
package core
import (
"os"
"path/filepath"
"plugin"
"strings"
"v2ray.com/core/app/log"
"v2ray.com/core/common/platform"
)
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
}

7
plugin_other.go Normal file
View File

@ -0,0 +1,7 @@
// +build !linux
package core
func LoadPlugins() error {
return nil
}