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

README.md

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/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
  --grpc-gateway_out=logtostderr=true:. \
  api/library.proto
protoc -I/usr/local/include -I. \
-I$GOPATH/src \
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--go_out=plugins=grpc:. \
api/library.proto

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:

bash add_books.sh

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

http://localhost:8181/listBooks
http://localhost:8181/searchBook
http://localhost:8181/addBook

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.