Skip to content
A simple library implementation in Go to demonstrate the workings of OPA and gRPC
Branch: master
Clone or download

A GRPC service in Go

To compile proto files, use the two commands -

protoc -I/usr/local/include -I. \
  -I$GOPATH/src \
  -I$GOPATH/src/ \
  --grpc-gateway_out=logtostderr=true:. \
protoc -I/usr/local/include -I. \
-I$GOPATH/src \
-I$GOPATH/src/ \
--go_out=plugins=grpc:. \

How to run the service

Run gRPC server in one terminal -

go run cmd/main.go

This will start two server, one gRPC at port :50051 and other HTTP on port :8181.

Now run OPA in other terminal -

opa run -a "localhost:8080" -s OPA/policy.rego OPA/users.json

Now add the books:


After that you can try calling all the functions on following urls -


Do not forget to add the input data in the body field of the POST/PUT request.

A sample input data is below -

    "user": {
        "userType": 2
    "book": {
      "isbn": "9488900377"
You can’t perform that action at this time.