Another refactor
This commit is contained in:
parent
2c9a6e3049
commit
f39c5778ce
@ -2,27 +2,33 @@ package main
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
const french = "French"
|
const (
|
||||||
const spanish = "Spanish"
|
french = "French"
|
||||||
const englishHelloPrefix = "Hello, "
|
spanish = "Spanish"
|
||||||
const frenchHelloPrefix = "Bonjour, "
|
|
||||||
const spanishHelloPrefix = "Hola, "
|
englishHelloPrefix = "Hello, "
|
||||||
|
frenchHelloPrefix = "Bonjour, "
|
||||||
|
spanishHelloPrefix = "Hola, "
|
||||||
|
)
|
||||||
|
|
||||||
func Hello(name string, language string) string {
|
func Hello(name string, language string) string {
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = "World"
|
name = "World"
|
||||||
}
|
}
|
||||||
|
|
||||||
prefix := englishHelloPrefix
|
return greetingPrefix(language) + name
|
||||||
|
}
|
||||||
|
|
||||||
|
func greetingPrefix(language string) (prefix string) {
|
||||||
switch language {
|
switch language {
|
||||||
case french:
|
case french:
|
||||||
prefix = frenchHelloPrefix
|
prefix = frenchHelloPrefix
|
||||||
case spanish:
|
case spanish:
|
||||||
prefix = spanishHelloPrefix
|
prefix = spanishHelloPrefix
|
||||||
|
default:
|
||||||
|
prefix = englishHelloPrefix
|
||||||
}
|
}
|
||||||
|
return
|
||||||
return prefix + name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user