Codebase list golang-github-go-kit-kit / 3b9658d9-4065-4804-9af8-16961c419f60/v0.4.0 examples / stringsvc2 / service.go
3b9658d9-4065-4804-9af8-16961c419f60/v0.4.0

Tree @3b9658d9-4065-4804-9af8-16961c419f60/v0.4.0 (Download .tar.gz)

service.go @3b9658d9-4065-4804-9af8-16961c419f60/v0.4.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")