mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-23 04:03:49 +00:00
Trackers: split file lines cross-platform way #4191
This commit is contained in:
parent
56fcb19578
commit
80d1d8a114
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user