greetings/greetings.go

19 lines
408 B
Go
Raw Normal View History

2024-09-26 15:34:35 +02:00
package greetings
2024-09-26 15:44:26 +02:00
import (
"errors"
"fmt"
)
2024-09-26 15:34:35 +02:00
// Hello returns a greeting for the named person.
func Hello(name string) string {
2024-09-26 15:44:26 +02:00
// If no name was given, return an error with a message.
if name == "" {
return "", errors.New("empty name")
}
2024-09-26 15:34:35 +02:00
// Return a greeting that embeds the name in a message.
message := fmt.Sprintf("Hi, %v. Welcome!", name)
2024-09-26 15:44:26 +02:00
return message, nil
2024-09-26 15:34:35 +02:00
}