mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
all: Simplify some method calls (#7499)
strings.Replace(a, b, c, -1) -> strings.ReplaceAll(a, b, c) (Go 1.12) and who knows what was up with that dialQueue.Sort() thing.
This commit is contained in:
parent
960e850a78
commit
8ef504f745
@ -37,7 +37,7 @@ type result struct {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
prefix := strings.ToUpper(strings.Replace(flag.Arg(0), "-", "", -1))
|
prefix := strings.ToUpper(strings.ReplaceAll(flag.Arg(0), "-", ""))
|
||||||
if len(prefix) > 7 {
|
if len(prefix) > 7 {
|
||||||
prefix = prefix[:7] + "-" + prefix[7:]
|
prefix = prefix[:7] + "-" + prefix[7:]
|
||||||
}
|
}
|
||||||
|
@ -725,8 +725,8 @@ func getReport(db *sql.DB) map[string]interface{} {
|
|||||||
|
|
||||||
if rep.NATType != "" {
|
if rep.NATType != "" {
|
||||||
natType := rep.NATType
|
natType := rep.NATType
|
||||||
natType = strings.Replace(natType, "unknown", "Unknown", -1)
|
natType = strings.ReplaceAll(natType, "unknown", "Unknown")
|
||||||
natType = strings.Replace(natType, "Symetric", "Symmetric", -1)
|
natType = strings.ReplaceAll(natType, "Symetric", "Symmetric")
|
||||||
add(featureGroups["Various"]["v3"], "NAT Type", natType, 1)
|
add(featureGroups["Various"]["v3"], "NAT Type", natType, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ func (t *quicListener) OnExternalAddressChanged(address *stun.Host, via string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *quicListener) serve(ctx context.Context) error {
|
func (t *quicListener) serve(ctx context.Context) error {
|
||||||
network := strings.Replace(t.uri.Scheme, "quic", "udp", -1)
|
network := strings.ReplaceAll(t.uri.Scheme, "quic", "udp")
|
||||||
|
|
||||||
packetConn, err := net.ListenPacket(network, t.uri.Host)
|
packetConn, err := net.ListenPacket(network, t.uri.Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -174,7 +174,7 @@ func (t *quicListener) WANAddresses() []*url.URL {
|
|||||||
|
|
||||||
func (t *quicListener) LANAddresses() []*url.URL {
|
func (t *quicListener) LANAddresses() []*url.URL {
|
||||||
addrs := []*url.URL{t.uri}
|
addrs := []*url.URL{t.uri}
|
||||||
network := strings.Replace(t.uri.Scheme, "quic", "udp", -1)
|
network := strings.ReplaceAll(t.uri.Scheme, "quic", "udp")
|
||||||
addrs = append(addrs, getURLsForAllAdaptersIfUnspecified(network, t.uri)...)
|
addrs = append(addrs, getURLsForAllAdaptersIfUnspecified(network, t.uri)...)
|
||||||
return addrs
|
return addrs
|
||||||
}
|
}
|
||||||
|
@ -478,7 +478,7 @@ func (s *service) dialDevices(ctx context.Context, now time.Time, cfg config.Con
|
|||||||
// doesn't have much effect, but it may result in getting up and running
|
// doesn't have much effect, but it may result in getting up and running
|
||||||
// quicker if only a subset of configured devices are actually reachable
|
// quicker if only a subset of configured devices are actually reachable
|
||||||
// (by prioritizing those that were reachable recently).
|
// (by prioritizing those that were reachable recently).
|
||||||
dialQueue.Sort(queue)
|
queue.Sort()
|
||||||
|
|
||||||
// Perform dials according to the queue, stopping when we've reached the
|
// Perform dials according to the queue, stopping when we've reached the
|
||||||
// allowed additional number of connections (if limited).
|
// allowed additional number of connections (if limited).
|
||||||
|
@ -252,8 +252,7 @@ func Canonicalize(file string) (string, error) {
|
|||||||
file = filepath.Clean(file)
|
file = filepath.Clean(file)
|
||||||
|
|
||||||
// It is not acceptable to attempt to traverse upwards.
|
// It is not acceptable to attempt to traverse upwards.
|
||||||
switch file {
|
if file == ".." {
|
||||||
case "..":
|
|
||||||
return "", errNotRelative
|
return "", errNotRelative
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(file, ".."+pathSep) {
|
if strings.HasPrefix(file, ".."+pathSep) {
|
||||||
|
@ -115,7 +115,7 @@ func expandLocations() error {
|
|||||||
newLocations := make(map[LocationEnum]string)
|
newLocations := make(map[LocationEnum]string)
|
||||||
for key, dir := range locationTemplates {
|
for key, dir := range locationTemplates {
|
||||||
for varName, value := range baseDirs {
|
for varName, value := range baseDirs {
|
||||||
dir = strings.Replace(dir, "${"+string(varName)+"}", value, -1)
|
dir = strings.ReplaceAll(dir, "${"+string(varName)+"}", value)
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
dir, err = fs.ExpandTilde(dir)
|
dir, err = fs.ExpandTilde(dir)
|
||||||
@ -197,5 +197,5 @@ func GetTimestamped(key LocationEnum) string {
|
|||||||
// 2006 replaced by 2015...
|
// 2006 replaced by 2015...
|
||||||
tpl := locations[key]
|
tpl := locations[key]
|
||||||
now := time.Now().Format("20060102-150405")
|
now := time.Now().Format("20060102-150405")
|
||||||
return strings.Replace(tpl, "${timestamp}", now, -1)
|
return strings.ReplaceAll(tpl, "${timestamp}", now)
|
||||||
}
|
}
|
||||||
|
@ -692,7 +692,7 @@ func (m *model) UsageReportingStats(report *contract.Report, version int, previe
|
|||||||
if strings.Contains(line, "**") {
|
if strings.Contains(line, "**") {
|
||||||
report.IgnoreStats.DoubleStars++
|
report.IgnoreStats.DoubleStars++
|
||||||
// Remove not to trip up star checks.
|
// Remove not to trip up star checks.
|
||||||
line = strings.Replace(line, "**", "", -1)
|
line = strings.ReplaceAll(line, "**", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(line, "*") {
|
if strings.Contains(line, "*") {
|
||||||
|
@ -203,15 +203,15 @@ func chunkify(s string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func unchunkify(s string) string {
|
func unchunkify(s string) string {
|
||||||
s = strings.Replace(s, "-", "", -1)
|
s = strings.ReplaceAll(s, "-", "")
|
||||||
s = strings.Replace(s, " ", "", -1)
|
s = strings.ReplaceAll(s, " ", "")
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func untypeoify(s string) string {
|
func untypeoify(s string) string {
|
||||||
s = strings.Replace(s, "0", "O", -1)
|
s = strings.ReplaceAll(s, "0", "O")
|
||||||
s = strings.Replace(s, "1", "I", -1)
|
s = strings.ReplaceAll(s, "1", "I")
|
||||||
s = strings.Replace(s, "8", "B", -1)
|
s = strings.ReplaceAll(s, "8", "B")
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ USER-AGENT: syncthing/1.0
|
|||||||
`
|
`
|
||||||
searchStr := fmt.Sprintf(tpl, deviceType, timeout/time.Second)
|
searchStr := fmt.Sprintf(tpl, deviceType, timeout/time.Second)
|
||||||
|
|
||||||
search := []byte(strings.Replace(searchStr, "\n", "\r\n", -1) + "\r\n")
|
search := []byte(strings.ReplaceAll(searchStr, "\n", "\r\n") + "\r\n")
|
||||||
|
|
||||||
l.Debugln("Starting discovery of device type", deviceType, "on", intf.Name)
|
l.Debugln("Starting discovery of device type", deviceType, "on", intf.Name)
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ func newExternal(cfg config.FolderConfiguration) Versioner {
|
|||||||
command := cfg.Versioning.Params["command"]
|
command := cfg.Versioning.Params["command"]
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
command = strings.Replace(command, `\`, `\\`, -1)
|
command = strings.ReplaceAll(command, `\`, `\\`)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := external{
|
s := external{
|
||||||
@ -81,7 +81,7 @@ func (v external) Archive(filePath string) error {
|
|||||||
|
|
||||||
for i, word := range words {
|
for i, word := range words {
|
||||||
for key, val := range context {
|
for key, val := range context {
|
||||||
word = strings.Replace(word, key, val, -1)
|
word = strings.ReplaceAll(word, key, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
words[i] = word
|
words[i] = word
|
||||||
|
Loading…
Reference in New Issue
Block a user