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:
Quentin McGaw
2022-05-27 15:49:41 +00:00
parent bd0868d764
commit 4bde50fb3a
10 changed files with 48 additions and 22 deletions

View File

@@ -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