From f39c5778ce0dd5a878196caed3913453429b237b Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 29 Sep 2023 11:03:02 -0400 Subject: [PATCH] Another refactor --- hello/hello.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/hello/hello.go b/hello/hello.go index ddb3c5c..f43f4da 100644 --- a/hello/hello.go +++ b/hello/hello.go @@ -2,27 +2,33 @@ package main import "fmt" -const french = "French" -const spanish = "Spanish" -const englishHelloPrefix = "Hello, " -const frenchHelloPrefix = "Bonjour, " -const spanishHelloPrefix = "Hola, " +const ( + french = "French" + spanish = "Spanish" + + englishHelloPrefix = "Hello, " + frenchHelloPrefix = "Bonjour, " + spanishHelloPrefix = "Hola, " +) func Hello(name string, language string) string { if name == "" { name = "World" } - prefix := englishHelloPrefix + return greetingPrefix(language) + name +} +func greetingPrefix(language string) (prefix string) { switch language { case french: prefix = frenchHelloPrefix case spanish: prefix = spanishHelloPrefix + default: + prefix = englishHelloPrefix } - - return prefix + name + return } func main() {