Trackers: split file lines cross-platform way #4191

This commit is contained in:
Alex Sharov 2022-05-18 10:28:14 +07:00 committed by GitHub
parent 56fcb19578
commit 80d1d8a114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,29 +1,47 @@
package trackers
import (
"bufio"
_ "embed"
"strings"
)
//go:embed trackerslist/trackers_best.txt
var best string
var Best = strings.Split(best, "\n\n")
var Best = split(best)
//go:embed trackerslist/trackers_all_https.txt
var https string
var Https = strings.Split(https, "\n\n")
var Https = split(https)
//go:embed trackerslist/trackers_all_http.txt
var http string
var Http = strings.Split(http, "\n\n")
var Http = split(http)
//go:embed trackerslist/trackers_all_udp.txt
var udp string
var Udp = strings.Split(udp, "\n\n")
var Udp = split(udp)
//go:embed trackerslist/trackers_all_ws.txt
var ws string
var Ws = strings.Split(ws, "\n\n")
var Ws = split(ws)
func split(txt string) (lines []string) {
sc := bufio.NewScanner(strings.NewReader(txt))
for sc.Scan() {
l := sc.Text()
l = strings.TrimSpace(l)
if len(l) == 0 {
continue
}
lines = append(lines, sc.Text())
}
if err := sc.Err(); err != nil {
panic(err)
}
return lines
}
func First(n int, in []string) (res []string) {
if n <= len(in) {