I have difficulties refactoring code in go, since the lint detects duplication of pattern but the function is different.
the code goes like this, it is implemented for grpc with protobuf definition
func (svc *UserService) CreateUser(ctx context.Context, req *pb.CreateUserRequest) (*pb.CreateUserResponse, error) {
err := svc.validateCreateUser(req)
if err != nil {
return nil, err
}
user, err := svc.repo.CreateUser(ctx, req)
if err != nil {
return nil, err
}
return user, nil
}
func (svc *UserService) UpdateUser(ctx context.Context, req *pb.UpdateUserRequest) (*pb.UpdateUserResponse, error) {
err := svc.validateUpdateUser(req)
if err != nil {
return nil, err
}
user, err := svc.repo.UpdateUser(ctx, req)
if err != nil {
return nil, err
}
return user, nil
}
thanks in advance.
I have no clue how to avoid duplication since the function also have different param type.