Codebase list golang-github-go-kit-kit / d2f2902b-79c4-43cd-8c09-341e33fc6017/v0.6.0 examples / stringsvc3 / service.go
d2f2902b-79c4-43cd-8c09-341e33fc6017/v0.6.0

Tree @d2f2902b-79c4-43cd-8c09-341e33fc6017/v0.6.0 (Download .tar.gz)

service.go @d2f2902b-79c4-43cd-8c09-341e33fc6017/v0.6.0raw · 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")

// ServiceMiddleware is a chainable behavior modifier for StringService.
type ServiceMiddleware func(StringService) StringService