OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / go-kit / kit / examples / stringsvc2 / service.go
1 package main
2
3 import (
4         "errors"
5         "strings"
6 )
7
8 // StringService provides operations on strings.
9 type StringService interface {
10         Uppercase(string) (string, error)
11         Count(string) int
12 }
13
14 type stringService struct{}
15
16 func (stringService) Uppercase(s string) (string, error) {
17         if s == "" {
18                 return "", ErrEmpty
19         }
20         return strings.ToUpper(s), nil
21 }
22
23 func (stringService) Count(s string) int {
24         return len(s)
25 }
26
27 // ErrEmpty is returned when an input string is empty.
28 var ErrEmpty = errors.New("empty string")