Open mithun26779 opened 4 years ago
still waiting for this issue
as the blog post says: this repo was a demonstration of the plugin possibilities on top of the branch modules
.
some time ago, the branch was improved and merged into the project, changing the interface to the final one described here: https://godoc.org/github.com/devopsfaith/krakend/transport/http/client/plugin
that's why your plugin is not being loaded (it should be at the beginning of your logs)
try renaming the type of your plugin from GRPCRegisterer
to ClientRegisterer
There are changes on plugin client interface https://github.com/devopsfaith/krakend/tree/master/transport/http/client/plugin So need update plugin.go
package main
import ( "context" "errors" "fmt" "net/http"
"github.com/kpacha/krakend-grpc-gateway-post/gateway" )
// ClientRegisterer is the symbol the plugin loader will try to load. It must implement the RegisterClient interface var ClientRegisterer = registerer("grpc-gateway-post")
type registerer string
func (r registerer) RegisterClients(f func( name string, handler func(context.Context, map[string]interface{}) (http.Handler, error), )) { f(string(r), r.registerClients) }
func (r registerer) registerClients(ctx context.Context, extra map[string]interface{}) (http.Handler, error) { // check the passed configuration and initialize the plugin name, ok := extra["name"].(string) if !ok { return nil, errors.New("wrong config") } if name != string(r) { return nil, fmt.Errorf("unknown register %s", name) } // return the actual handler wrapping or your custom logic so it can be used as a replacement for the default http client cfg := parse(extra) if cfg == nil { return nil, errors.New("wrong config") } if cfg.name != string(r) { return nil, fmt.Errorf("unknown register %s", cfg.name) } return gateway.New(ctx, cfg.helloEndpoint, cfg.routeEndpoint) }
func init() { fmt.Println("krakend-example client plugin loaded!!!") }
func main() {}
func parse(extra map[string]interface{}) *opts { name, ok := extra["name"].(string) if !ok { return nil }
rawEs, ok := extra["endpoints"] if !ok { return nil } es, ok := rawEs.([]interface{}) if !ok || len(es) < 2 { return nil } endpoints := make([]string, len(es)) for i, e := range es { endpoints[i] = e.(string) }
return &opts{ name: name, helloEndpoint: endpoints[0], routeEndpoint: endpoints[1], } }
type opts struct { name string helloEndpoint string routeEndpoint string }
followed all the instructions in tutorial https://www.krakend.io/blog/krakend-grpc-gateway-plugin/ on a Mac. After installing krakend and creating json from the tutorial, curl is returning empty. Please help.
"krakend run -d -c krakend.json"
curl -i localhost:8000/user/foo/407838351/-746143763 HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 X-Krakend: Version 1.1.0 X-Krakend-Completed: false Date: Mon, 06 Apr 2020 14:15:26 GMT Content-Length: 3
{}