diff --git a/plugin.go b/plugin.go index dbd9b4c93..6d942a7ed 100644 --- a/plugin.go +++ b/plugin.go @@ -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 -} diff --git a/plugin_linux.go b/plugin_linux.go new file mode 100644 index 000000000..ae595ba6e --- /dev/null +++ b/plugin_linux.go @@ -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 +} diff --git a/plugin_other.go b/plugin_other.go new file mode 100644 index 000000000..718be38f7 --- /dev/null +++ b/plugin_other.go @@ -0,0 +1,7 @@ +// +build !linux + +package core + +func LoadPlugins() error { + return nil +}