Add hello package with tests
This commit is contained in:
33
hello/hello.go
Normal file
33
hello/hello.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
const spanish = "Spanish"
|
||||
const french = "French"
|
||||
|
||||
const englishHelloPrefix = "Hello, "
|
||||
const spanishHelloPrefix = "Hola, "
|
||||
const frenchHelloPrefix = "Bonjour, "
|
||||
|
||||
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", ""))
|
||||
}
|
||||
Reference in New Issue
Block a user