Skip to content

Instantly share code, notes, and snippets.

@vtolstov
Last active March 1, 2019 16:17
Show Gist options
  • Save vtolstov/992947fd88ba0fa465bfbe03ceadbbac to your computer and use it in GitHub Desktop.
Save vtolstov/992947fd88ba0fa465bfbe03ceadbbac to your computer and use it in GitHub Desktop.
package policy
import (
"context"
"github.com/micro/go-micro/client"
"github.com/micro/go-micro/server"
"unistack.org/centralv2/service/policy/policypb"
)
func NewHandlerWrapper(copts ...client.Option) server.HandlerWrapper {
return func(fn server.HandlerFunc) server.HandlerFunc {
return func(ctx context.Context, req server.Request, rsp interface{}) error {
pc := policypb.NewPolicyService(policypb.SvcName, client.NewClient(copts...))
preq := &policypb.PolicyCheckReq{
Action: req.Service() + "." + req.Endpoint(),
User: uid,
Resource: rid,
}
_, err := pc.Check(ctx, preq)
if err == nil {
err = fn(ctx, req, rsp)
}
return err
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment