forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require goplugin build flag to enable go plugin support (influxdata#6393
- Loading branch information
1 parent
3bd9167
commit c21f77f
Showing
3 changed files
with
53 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// +build !goplugin | ||
|
||
package goplugin | ||
|
||
import "errors" | ||
|
||
func LoadExternalPlugins(rootDir string) error { | ||
return errors.New("go plugin support is not enabled") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// +build goplugin | ||
|
||
package goplugin | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"plugin" | ||
"strings" | ||
) | ||
|
||
// loadExternalPlugins loads external plugins from shared libraries (.so, .dll, etc.) | ||
// in the specified directory. | ||
func LoadExternalPlugins(rootDir string) error { | ||
return filepath.Walk(rootDir, func(pth string, info os.FileInfo, err error) error { | ||
// Stop if there was an error. | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Ignore directories. | ||
if info.IsDir() { | ||
return nil | ||
} | ||
|
||
// Ignore files that aren't shared libraries. | ||
ext := strings.ToLower(path.Ext(pth)) | ||
if ext != ".so" && ext != ".dll" { | ||
return nil | ||
} | ||
|
||
// Load plugin. | ||
_, err = plugin.Open(pth) | ||
if err != nil { | ||
return fmt.Errorf("error loading %s: %s", pth, err) | ||
} | ||
|
||
return nil | ||
}) | ||
} |