Files
platform/conv/country.go
T
2026-07-20 00:15:42 +02:00

22 lines
635 B
Go

package conv
import "strings"
// CountryFromHost extracts a country code from a hostname (or URL) by looking
// for known subdomain suffixes. Returns "se" when no country is detected.
//
// This replaces three duplicated implementations across the cart, checkout,
// and tracking services. The detection is deliberately coarse — hostnames
// like "shop-no.example.com" and URLs like "https://shop-no.example.com/page"
// both match.
func CountryFromHost(host string) string {
lower := strings.ToLower(host)
if strings.Contains(lower, "-no") {
return "no"
}
if strings.Contains(lower, "-se") {
return "se"
}
return "se"
}