github.com/dbernstein1/tyk@v2.9.0-beta9-dl-apic+incompatible/goplugin/goplugin.go (about) 1 // +build goplugin 2 3 package goplugin 4 5 import ( 6 "errors" 7 "net/http" 8 "plugin" 9 ) 10 11 func GetHandler(path string, symbol string) (http.HandlerFunc, error) { 12 // try to load plugin 13 loadedPlugin, err := plugin.Open(path) 14 if err != nil { 15 return nil, err 16 } 17 18 // try to lookup function symbol 19 funcSymbol, err := loadedPlugin.Lookup(symbol) 20 if err != nil { 21 return nil, err 22 } 23 24 // try to cast symbol to real func 25 pluginHandler, ok := funcSymbol.(func(http.ResponseWriter, *http.Request)) 26 if !ok { 27 return nil, errors.New("could not cast function symbol to http.HandlerFunc") 28 } 29 30 return pluginHandler, nil 31 }