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

@@ -12,6 +12,8 @@ import (
"github.com/qdm12/gluetun/internal/updater/openvpn"
"github.com/qdm12/gluetun/internal/updater/resolver"
"github.com/qdm12/gluetun/internal/updater/unzip"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
var ErrNotEnoughServers = errors.New("not enough servers found")
@@ -32,16 +34,17 @@ func GetServers(ctx context.Context, unzipper unzip.Unzipper,
}
hts := make(hostToServer)
titleCaser := cases.Title(language.English)
for fileName, content := range tcpContents {
const tcp, udp = true, false
newWarnings := addServerFromOvpn(fileName, content, hts, tcp, udp)
newWarnings := addServerFromOvpn(fileName, content, hts, tcp, udp, titleCaser)
warnings = append(warnings, newWarnings...)
}
for fileName, content := range udpContents {
const tcp, udp = false, true
newWarnings := addServerFromOvpn(fileName, content, hts, tcp, udp)
newWarnings := addServerFromOvpn(fileName, content, hts, tcp, udp, titleCaser)
warnings = append(warnings, newWarnings...)
}
@@ -72,12 +75,12 @@ func GetServers(ctx context.Context, unzipper unzip.Unzipper,
}
func addServerFromOvpn(fileName string, content []byte,
hts hostToServer, tcp, udp bool) (warnings []string) {
hts hostToServer, tcp, udp bool, titleCaser cases.Caser) (warnings []string) {
if !strings.HasSuffix(fileName, ".ovpn") {
return nil // not an OpenVPN file
}
country, city := parseFilename(fileName)
country, city := parseFilename(fileName, titleCaser)
host, warning, err := openvpn.ExtractHost(content)
if warning != "" {