Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
37 lines
924 B
Go
37 lines
924 B
Go
package greet
|
|
|
|
import (
|
|
"context"
|
|
|
|
"dance-lessons-coach/pkg/auth"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type Service struct{}
|
|
|
|
func NewService() *Service {
|
|
return &Service{}
|
|
}
|
|
|
|
// Greet returns a greeting message for the given name.
|
|
// If name is empty, it checks for authenticated user and uses their username.
|
|
// If no authenticated user and no name, it defaults to "world".
|
|
// Implements the Greeter interface.
|
|
func (s *Service) Greet(ctx context.Context, name string) string {
|
|
log.Trace().Ctx(ctx).Str("name", name).Msg("Greet function called")
|
|
|
|
// If no name provided, check for authenticated user
|
|
if name == "" {
|
|
if authenticatedUser, ok := auth.GetAuthenticatedUserFromContext(ctx); ok {
|
|
name = authenticatedUser.Username
|
|
log.Trace().Ctx(ctx).Str("authenticated_user", name).Msg("Using authenticated username for greeting")
|
|
}
|
|
}
|
|
|
|
if name == "" {
|
|
return "Hello world!"
|
|
}
|
|
return "Hello " + name + "!"
|
|
}
|