fix plugin file path

This commit is contained in:
Fabricio 2019-03-12 19:39:18 -03:00
parent b983f2dcf4
commit 857808cd37

11
main.go
View file

@ -13,6 +13,7 @@ import (
"net/http/httputil" "net/http/httputil"
"net/url" "net/url"
"os" "os"
"path/filepath"
"plugin" "plugin"
"strings" "strings"
@ -129,7 +130,13 @@ func NewDashboardItemInfoHandler(list *CaptureList) http.HandlerFunc {
// NewPlugin loads plugin files in the current directory. They are loaded sorted by filename. // NewPlugin loads plugin files in the current directory. They are loaded sorted by filename.
func NewPlugin(next http.HandlerFunc) http.HandlerFunc { func NewPlugin(next http.HandlerFunc) http.HandlerFunc {
files, err := ioutil.ReadDir(".") ex, err := os.Executable()
if err != nil {
fmt.Println("error: could not get executable:", err)
return next
}
exPath := filepath.Dir(ex)
files, err := ioutil.ReadDir(exPath)
if err != nil { if err != nil {
fmt.Println("error: could not read directory:", err) fmt.Println("error: could not read directory:", err)
return next return next
@ -140,7 +147,7 @@ func NewPlugin(next http.HandlerFunc) http.HandlerFunc {
} }
if strings.HasSuffix(file.Name(), ".so") { if strings.HasSuffix(file.Name(), ".so") {
fmt.Printf("loading plugin '%s'\n", file.Name()) fmt.Printf("loading plugin '%s'\n", file.Name())
p, err := plugin.Open(file.Name()) p, err := plugin.Open(exPath + "/" + file.Name())
if err != nil { if err != nil {
fmt.Println("error: could not open plugin:", err) fmt.Println("error: could not open plugin:", err)
os.Exit(1) os.Exit(1)