protoc-gen-go-micro/vendor/github.com/go-kit/kit/examples/stringsvc2/service.go
2017-03-31 18:01:58 +02:00

29 lines
504 B
Go

package main
import (
"errors"
"strings"
)
// StringService provides operations on strings.
type StringService interface {
Uppercase(string) (string, error)
Count(string) int
}
type stringService struct{}
func (stringService) Uppercase(s string) (string, error) {
if s == "" {
return "", ErrEmpty
}
return strings.ToUpper(s), nil
}
func (stringService) Count(s string) int {
return len(s)
}
// ErrEmpty is returned when an input string is empty.
var ErrEmpty = errors.New("empty string")