You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB
Go

// Provides a Hello world example with tests
package main
import (
"fmt"
)
// Constants can be grouped in a block.
// Add a line between related consts for
// readbility
const (
french = "French"
spanish = "Spanish"
englishHelloPrefix = "Hello, "
spanishHelloPrefix = "Hola, "
frenchHelloPrefix = "Bonjour, "
)
// Hello prints the string "Hello, world"
func Hello(name string, language string) string {
if name == "" {
name = "World"
}
return greetingPrefix(language) + name
}
// greetingPrefix Using a named return value will initialize a "zero value"
// variable which as you can see below can be assigned to.
// this will display in Go Doc for your function.
// Lower case letter functions are "private" functions. They are internal to implementation.
func greetingPrefix(language string) (prefix string) {
switch language {
case french:
prefix = frenchHelloPrefix
case spanish:
prefix = spanishHelloPrefix
default:
prefix = englishHelloPrefix
}
// we use names return value in function signature
return
}
func main() {
fmt.Println(Hello("world", ""))
}