chore(all): use casers instead of strings.Title
- Add `golang.org/x/text` dependency - Update code to use `cases.Title(language.English)`
This commit is contained in:
@@ -6,11 +6,12 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"golang.org/x/text/cases"
|
||||
)
|
||||
|
||||
var errCountryCodeUnknown = errors.New("country code is unknown")
|
||||
|
||||
func parseFilename(fileName, hostname string) (
|
||||
func parseFilename(fileName, hostname string, titleCaser cases.Caser) (
|
||||
country, city string, err error) {
|
||||
const prefix = "ipvanish-"
|
||||
s := strings.TrimPrefix(fileName, prefix)
|
||||
@@ -28,11 +29,11 @@ func parseFilename(fileName, hostname string) (
|
||||
if !ok {
|
||||
return "", "", fmt.Errorf("%w: %s", errCountryCodeUnknown, countryCode)
|
||||
}
|
||||
country = strings.Title(country)
|
||||
country = titleCaser.String(country)
|
||||
|
||||
if len(parts) > 1 {
|
||||
city = strings.Join(parts[1:], " ")
|
||||
city = strings.Title(city)
|
||||
city = titleCaser.String(city)
|
||||
}
|
||||
|
||||
return country, city, nil
|
||||
|
||||
Reference in New Issue
Block a user