Skip to content

Commit e56ed18

Browse files
committed
Also show sponsor info in server list
1 parent 9b7219a commit e56ed18

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

defs/server.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,24 @@ func (s *Server) GetURL() (*url.URL, error) {
424424
}
425425
return u, nil
426426
}
427+
428+
// Sponsor returns the sponsor's info
429+
func (s *Server) Sponsor() string {
430+
var sponsorMsg string
431+
if s.SponsorName != "" {
432+
sponsorMsg += s.SponsorName
433+
434+
if s.SponsorURL != "" {
435+
su, err := url.Parse(s.SponsorURL)
436+
if err != nil {
437+
log.Debugf("Sponsor URL is invalid: %s", s.SponsorURL)
438+
} else {
439+
if su.Scheme == "" {
440+
su.Scheme = "https"
441+
}
442+
sponsorMsg += " @ " + su.String()
443+
}
444+
}
445+
}
446+
return sponsorMsg
447+
}

speedtest/helper.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"math"
99
"mime/multipart"
1010
"net/http"
11-
"net/url"
1211
"strconv"
1312
"strings"
1413
"time"
@@ -46,23 +45,7 @@ func doSpeedTest(c *cli.Context, servers []defs.Server, telemetryServer defs.Tel
4645

4746
log.Infof("Selected server: %s [%s]", currentServer.Name, u.Hostname())
4847

49-
var sponsorMsg string
50-
if currentServer.SponsorName != "" {
51-
sponsorMsg += currentServer.SponsorName
52-
53-
if currentServer.SponsorURL != "" {
54-
su, err := url.Parse(currentServer.SponsorURL)
55-
if err != nil {
56-
log.Debugf("Sponsor URL is invalid: %s", currentServer.SponsorURL)
57-
} else {
58-
if su.Scheme == "" {
59-
su.Scheme = "https"
60-
}
61-
sponsorMsg += " @ " + su.String()
62-
}
63-
}
64-
}
65-
if sponsorMsg != "" {
48+
if sponsorMsg := currentServer.Sponsor(); sponsorMsg != "" {
6649
log.Infof("Sponsored by: %s", sponsorMsg)
6750
}
6851

speedtest/speedtest.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"errors"
7+
"fmt"
78
"io/ioutil"
89
"net"
910
"net/http"
@@ -235,7 +236,11 @@ func SpeedTest(c *cli.Context) error {
235236
// if --list is given, list all the servers fetched and exit
236237
if c.Bool(defs.OptionList) {
237238
for idx, svr := range servers {
238-
log.Warnf("%d: %s (%s)", idx, svr.Name, svr.Server)
239+
var sponsorMsg string
240+
if svr.Sponsor() != "" {
241+
sponsorMsg = fmt.Sprintf(" [Sponsor: %s]", svr.Sponsor())
242+
}
243+
log.Warnf("%d: %s (%s) %s", idx, svr.Name, svr.Server, sponsorMsg)
239244
}
240245
return nil
241246
}

0 commit comments

Comments
 (0)