learn-go-with-tests/hello.go

30 lines
455 B
Go
Raw Normal View History

2022-01-26 12:52:16 +00:00
package main
import "fmt"
2022-01-26 18:00:00 +00:00
const englishHelloPrefix = "Hello, "
2022-01-27 00:16:56 +00:00
const welsh = "Welsh"
const welshHelloPrefix = "Helo, "
2022-01-26 18:00:00 +00:00
2022-01-27 00:11:38 +00:00
func Hello(name string, language string) string {
if name == "" {
name = "World"
}
return greetingPrefix(language) + name
}
func greetingPrefix(language string) (prefix string) {
prefix = englishHelloPrefix
2022-01-27 00:19:28 +00:00
2022-01-27 00:16:56 +00:00
if language == welsh {
2022-01-27 00:19:28 +00:00
prefix = welshHelloPrefix
2022-01-27 00:11:38 +00:00
}
return
2022-01-26 13:12:15 +00:00
}
2022-01-26 12:52:16 +00:00
func main() {
2022-01-27 00:11:38 +00:00
fmt.Println(Hello("Oliver", ""))
2022-01-26 12:52:16 +00:00
}