Instantly share code, notes, and snippets.

Embed
What would you like to do?
lorem-grpc model layer
package lorem_grpc
import (
"context"
"github.com/ru-rocker/gokit-playground/lorem-grpc/pb"
)
//Encode and Decode Lorem Request
func EncodeGRPCLoremRequest(_ context.Context, r interface{}) (interface{}, error) {
req := r.(LoremRequest)
return &pb.LoremRequest{
RequestType: req.RequestType,
Max: req.Max,
Min: req.Min,
} , nil
}
func DecodeGRPCLoremRequest(ctx context.Context, r interface{}) (interface{}, error) {
req := r.(*pb.LoremRequest)
return LoremRequest{
RequestType: req.RequestType,
Max: req.Max,
Min: req.Min,
}, nil
}
// Encode and Decode Lorem Response
func EncodeGRPCLoremResponse(_ context.Context, r interface{}) (interface{}, error) {
resp := r.(LoremResponse)
return &pb.LoremResponse{
Message: resp.Message,
Err: resp.Err,
}, nil
}
func DecodeGRPCLoremResponse(_ context.Context, r interface{}) (interface{}, error) {
resp := r.(*pb.LoremResponse)
return LoremResponse{
Message: resp.Message,
Err: resp.Err,
}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment