Skip to content

Instantly share code, notes, and snippets.

@junereycasuga
Created November 20, 2020 09:33
Show Gist options
  • Save junereycasuga/760141b5765f920d02fdacd4450cc23e to your computer and use it in GitHub Desktop.
Save junereycasuga/760141b5765f920d02fdacd4450cc23e to your computer and use it in GitHub Desktop.
gokit-grpc-demo endpoints/endpointsgo
package endpoints
import (
"context"
"github.com/go-kit/kit/endpoint"
"github.com/junereycasuga/gokit-grpc-demo/service"
)
// Endpoints struct holds the list of endpoints definition
type Endpoints struct {
Add endpoint.Endpoint
}
// MathReq struct holds the endpoint request definition
type MathReq struct {
NumA float32
NumB float32
}
// MathResp struct holds the endpoint response definition
type MathResp struct {
Result float32
}
// MakeEndpoints func initializes the Endpoint instances
func MakeEndpoints(s service.Service) Endpoints {
return Endpoints{
Add: makeAddEndpoint(s),
}
}
func makeAddEndpoint(s service.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
req := request.(MathReq)
result, _ := s.Add(ctx, req.NumA, req.NumB)
return MathResp{Result: result}, nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment