From 507e0c176b0e92e11cac14eadc88a2e7f903351a Mon Sep 17 00:00:00 2001 From: Pedro Correa Date: Mon, 4 Mar 2024 16:34:29 -0300 Subject: [PATCH] :recycle: (Go) prefix in hello world and const declaration --- Go/hello.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Go/hello.go b/Go/hello.go index c6b372e..7e5f4c3 100644 --- a/Go/hello.go +++ b/Go/hello.go @@ -2,27 +2,33 @@ package main import "fmt" -const spanish = "Spanish" -const french = "French" -const englishHelloPrefix = "Hello, " -const spanishHelloPrefix = "Hola, " -const frenchHelloPrefix = "Bonjour, " +const ( + spanish = "Spanish" + french = "French" -func Hello(name string, language string) string { - if name == "" { - name = "world" - } - - prefix := englishHelloPrefix + englishHelloPrefix = "Hello, " + spanishHelloPrefix = "Hola, " + frenchHelloPrefix = "Bonjour, " +) +func greetingPrefix(language string) (prefix string) { switch language { case french: prefix = frenchHelloPrefix case spanish: prefix = spanishHelloPrefix + default: + prefix = englishHelloPrefix + } + return +} + +func Hello(name string, language string) string { + if name == "" { + name = "world" } - return prefix + name + return greetingPrefix(language) + name } func main() { -- 2.51.2