Codebase list golang-github-go-kit-kit / bd82318c-0d39-41b5-bf0b-5c2310cdd036/main examples / stringsvc2 / service.go
bd82318c-0d39-41b5-bf0b-5c2310cdd036/main

Tree @bd82318c-0d39-41b5-bf0b-5c2310cdd036/main (Download .tar.gz)

service.go @bd82318c-0d39-41b5-bf0b-5c2310cdd036/mainraw · history · blame

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")