learn-go-with-tests/hello.go
Oliver Davies 4b865f379b
Some checks failed
CI / test (push) Has been cancelled
Refactor: extract greetingPrefix function
2022-01-27 00:22:20 +00:00

30 lines
455 B
Go

package main
import "fmt"
const englishHelloPrefix = "Hello, "
const welsh = "Welsh"
const welshHelloPrefix = "Helo, "
func Hello(name string, language string) string {
if name == "" {
name = "World"
}
return greetingPrefix(language) + name
}
func greetingPrefix(language string) (prefix string) {
prefix = englishHelloPrefix
if language == welsh {
prefix = welshHelloPrefix
}
return
}
func main() {
fmt.Println(Hello("Oliver", ""))
}