Maintenance: refactor servers updater code
- Require at least 80% of number of servers now to pass - Each provider is in its own package with a common structure - Unzip package with unzipper interface - Openvpn package with extraction and download functions
This commit is contained in:
39
internal/updater/providers/fastestvpn/filename.go
Normal file
39
internal/updater/providers/fastestvpn/filename.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package fastestvpn
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var errFilenameNoProtocolSuffix = errors.New("filename does not have a protocol suffix")
|
||||
|
||||
var trailNumberExp = regexp.MustCompile(`[0-9]+$`)
|
||||
|
||||
func parseFilename(fileName string) (
|
||||
country string, tcp, udp bool, err error,
|
||||
) {
|
||||
const (
|
||||
tcpSuffix = "-TCP.ovpn"
|
||||
udpSuffix = "-UDP.ovpn"
|
||||
)
|
||||
var suffix string
|
||||
switch {
|
||||
case strings.HasSuffix(fileName, tcpSuffix):
|
||||
suffix = tcpSuffix
|
||||
tcp = true
|
||||
case strings.HasSuffix(fileName, udpSuffix):
|
||||
suffix = udpSuffix
|
||||
udp = true
|
||||
default:
|
||||
return "", false, false, fmt.Errorf("%w: %s",
|
||||
errFilenameNoProtocolSuffix, fileName)
|
||||
}
|
||||
|
||||
countryWithNumber := strings.TrimSuffix(fileName, suffix)
|
||||
number := trailNumberExp.FindString(countryWithNumber)
|
||||
country = countryWithNumber[:len(countryWithNumber)-len(number)]
|
||||
|
||||
return country, tcp, udp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user