exit on plugin failure

This commit is contained in:
Fabricio 2019-03-10 13:05:05 -03:00
parent 61fcffb47f
commit 6f8bb9e9da

View file

@ -12,6 +12,7 @@ import (
"net/http/httptest" "net/http/httptest"
"net/http/httputil" "net/http/httputil"
"net/url" "net/url"
"os"
"plugin" "plugin"
"strings" "strings"
@ -142,17 +143,17 @@ func NewPlugin(next http.HandlerFunc) http.HandlerFunc {
p, err := plugin.Open(file.Name()) p, err := plugin.Open(file.Name())
if err != nil { if err != nil {
fmt.Println("error: could not open plugin:", err) fmt.Println("error: could not open plugin:", err)
continue os.Exit(1)
} }
fn, err := p.Lookup("Handler") fn, err := p.Lookup("Handler")
if err != nil { if err != nil {
fmt.Println("error: could not find plugin Handler function:", err) fmt.Println("error: could not find plugin Handler function:", err)
continue os.Exit(1)
} }
pluginHandler, ok := fn.(func(http.HandlerFunc) http.HandlerFunc) pluginHandler, ok := fn.(func(http.HandlerFunc) http.HandlerFunc)
if !ok { if !ok {
fmt.Println("error: plugin Handler function should be 'func(http.HandlerFunc) http.HandlerFunc'") fmt.Println("error: plugin Handler function should be 'func(http.HandlerFunc) http.HandlerFunc'")
continue os.Exit(1)
} }
next = pluginHandler(next) next = pluginHandler(next)
} }