localization

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package localization provides generic, app-agnostic country/currency/ timezone/phone reference data and resolution — a Country registry, an AccountCountry vs DetectedCountry resolution middleware, and IP-based country detection — for any nebularcore-based product operating in more than one country. It intentionally carries no payment-provider or other app-specific business logic; host apps layer that on top, keyed by the ISO country code this module resolves.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CountryResolver

type CountryResolver interface {
	Resolve(ctx context.Context, code string) (*models.Country, error)
	Default(ctx context.Context) (*models.Country, error)
}

CountryResolver resolves ISO country codes to full Country reference records. Implementations may cache, since the countries table is admin-editable reference data read on every request via the module's middleware, not something that needs a fresh query each time.

func NewCountryResolver

func NewCountryResolver(repo repositories.CountryRepository, defaultCode string) CountryResolver

NewCountryResolver builds a cached CountryResolver. defaultCode is the country returned by Default (and used as a resolution fallback by consumers) — typically the host app's primary/home country.

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module implements the nebularcore module interface for country/locale resolution.

func New

func New() *Module

New creates a new localization module.

func (*Module) Configure

func (m *Module) Configure(cfg coreConfig.Config) error

func (*Module) Dependencies

func (m *Module) Dependencies() []string

Dependencies returns the module's dependencies. Localization has none — it's foundational reference data other modules (auth, billing, etc.) depend on, not the reverse.

func (*Module) GetMigrationSources

func (m *Module) GetMigrationSources(_ string) []migrationRunner.Source

func (*Module) Initialize

func (m *Module) Initialize(_ context.Context, db *gorm.DB, router *gin.Engine) error

func (*Module) MigrationsDir

func (m *Module) MigrationsDir() string

func (*Module) Name

func (m *Module) Name() string

func (*Module) Namespace

func (m *Module) Namespace() module.ModuleNamespace

func (*Module) NewConfig

func (m *Module) NewConfig() coreConfig.Config

func (*Module) ProvidesMigrations

func (m *Module) ProvidesMigrations() bool

func (*Module) Repository

func (m *Module) Repository() repositories.CountryRepository

Repository exposes the module's CountryRepository, e.g. for an admin handler toggling IsActive.

func (*Module) Resolver

func (m *Module) Resolver() CountryResolver

Resolver exposes the module's CountryResolver for other modules/host-app code to use directly (e.g. billing sourcing a currency code, or account-country resolvers wanting to validate a code exists).

func (*Module) Shutdown

func (m *Module) Shutdown(_ context.Context) error

func (*Module) Version

func (m *Module) Version() string

func (*Module) WithAccountCountryResolver

func (m *Module) WithAccountCountryResolver(fn middleware.AccountCountryResolverFunc) *Module

WithAccountCountryResolver registers the host app's lookup from user ID to home-country code (e.g. reading Address.Country off the user's profile). Without this, AccountCountry is never resolved and only DetectedCountry (IP-based) is available.

func (*Module) WithAuthenticatedUserIDFunc

func (m *Module) WithAuthenticatedUserIDFunc(fn middleware.AuthenticatedUserIDFunc) *Module

WithAuthenticatedUserIDFunc sets how the middleware reads the current request's authenticated user ID (e.g. from whatever the host app's auth middleware set on the gin context).

func (*Module) WithClientIPFunc

func (m *Module) WithClientIPFunc(fn middleware.ClientIPFunc) *Module

WithClientIPFunc sets how the middleware extracts a trusted client IP (or pre-extracted header value, for a CloudflareHeaderResolver) from each request. Must be set before Initialize for GeoIP-based DetectedCountry resolution to do anything — deliberately not defaulted to gin's c.ClientIP(), since that's only trustworthy once the host app has correctly configured SetTrustedProxies/ForwardedByClientIP for its real proxy/LB.

func (*Module) WithCountryRepository

func (m *Module) WithCountryRepository(repo repositories.CountryRepository) *Module

WithCountryRepository overrides the repository (e.g. to inject a fake in tests).

func (*Module) WithCountryResolver

func (m *Module) WithCountryResolver(resolver CountryResolver) *Module

WithCountryResolver overrides the resolver (e.g. to inject a fake in tests, or a differently-tuned cache).

func (*Module) WithGeoResolver

func (m *Module) WithGeoResolver(resolver geoip.Resolver) *Module

WithGeoResolver overrides IP-resolution entirely (e.g. to inject a fake in tests, or a provider not covered by config.GeoIPProvider).

Directories

Path Synopsis
Package geoip resolves a client IP address to a best-guess ISO country code, for DetectedCountry only (display/discovery convenience — never authoritative for billing; see the localization module's middleware).
Package geoip resolves a client IP address to a best-guess ISO country code, for DetectedCountry only (display/discovery convenience — never authoritative for billing; see the localization module's middleware).
Package middleware resolves per-request country context and injects it into the gin context, mirroring modules/auth/middleware's c.Set("user", ...) pattern.
Package middleware resolves per-request country context and injects it into the gin context, mirroring modules/auth/middleware's c.Set("user", ...) pattern.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL