go-i18n/default_service.go
Virgil 4d8b288a9c refactor(i18n): centralize default-service wrappers
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-02 09:52:50 +00:00

17 lines
437 B
Go

package i18n
// withDefaultService runs fn when the default service is available.
func withDefaultService(fn func(*Service)) {
if svc := Default(); svc != nil {
fn(svc)
}
}
// defaultServiceValue returns the value produced by fn when the default
// service exists, or fallback otherwise.
func defaultServiceValue[T any](fallback T, fn func(*Service) T) T {
if svc := Default(); svc != nil {
return fn(svc)
}
return fallback
}