learn-go-with-tests/hello/hello.go
2023-09-29 11:03:02 -04:00

37 lines
574 B
Go

package main
import "fmt"
const (
french = "French"
spanish = "Spanish"
englishHelloPrefix = "Hello, "
frenchHelloPrefix = "Bonjour, "
spanishHelloPrefix = "Hola, "
)
func Hello(name string, language string) string {
if name == "" {
name = "World"
}
return greetingPrefix(language) + name
}
func greetingPrefix(language string) (prefix string) {
switch language {
case french:
prefix = frenchHelloPrefix
case spanish:
prefix = spanishHelloPrefix
default:
prefix = englishHelloPrefix
}
return
}
func main() {
fmt.Println(Hello("world", ""))
}