Exemplo n.º 1
0
func (e *Reverseservice) HandleReverse(req *pb.ReverseRequest, resp *pb.ReverseResponse) error {
	// Get Unicode code points.
	n := 0
	rune := make([]rune, len(req.GetNormalString()))
	for _, r := range req.GetNormalString() {
		rune[n] = r
		n++
	}
	rune = rune[0:n]
	// Reverse
	for i := 0; i < n/2; i++ {
		rune[i], rune[n-1-i] = rune[n-1-i], rune[i]
	}
	// Convert back to UTF-8.
	resp.ReversedString = proto.String(string(rune))

	// No errors occurred
	return nil
}
Exemplo n.º 2
0
func (t *ReverseService) HandleReverse(req *pb.ReverseRequest, resp *pb.ReverseResponse) error {
	resp.ReversedString = proto.String("tset")
	return nil
}