Public Access
40 lines
1.0 KiB
Smarty
40 lines
1.0 KiB
Smarty
package gapi
|
|
|
|
import (
|
|
"context"
|
|
|
|
"{{ .ModuleName }}/pb" // We need the module name to import pb correctly!
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
"google.golang.org/genproto/googleapis/rpc/errdetails"
|
|
)
|
|
|
|
func (s *Server) {{ .Name }}(ctx context.Context, req *pb.{{ .Name }}Request) (*pb.{{ .Name }}Response, error) {
|
|
violations := validate{{ .Name }}Request(req)
|
|
if violations != nil {
|
|
return nil, invalidArgumentError(violations)
|
|
}
|
|
|
|
// TODO: Call service layer
|
|
// result, err := s.service.{{ .Name }}(ctx, ...)
|
|
|
|
/*
|
|
if err != nil {
|
|
return nil, status.Errorf(codes.Internal, "failed to execute: %v", err)
|
|
}
|
|
*/
|
|
|
|
resp := &pb.{{ .Name }}Response{
|
|
// TODO: Map result to response
|
|
}
|
|
return resp, nil
|
|
}
|
|
|
|
func validate{{ .Name }}Request(req *pb.{{ .Name }}Request) (violations []*errdetails.BadRequest_FieldViolation) {
|
|
// TODO: Add validation logic
|
|
// if err := val.ValidateString(req.GetField()); err != nil {
|
|
// violations = append(violations, fieldViolation("field", err))
|
|
// }
|
|
return violations
|
|
}
|