diff --git a/build.sh b/build.sh index b3f4fddc4..3cb8f721b 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ set -euo pipefail IFS=$'\n\t' -DOCKERIMGV=1.4-1 +DOCKERIMGV=1.4-2 case "${1:-default}" in default) @@ -113,7 +113,11 @@ case "${1:-default}" in -v $(pwd):/go/src/github.com/syncthing/syncthing \ -w /go/src/github.com/syncthing/syncthing \ syncthing/build:$DOCKERIMGV \ - sh -c './build.sh clean && ./build.sh all && STTRACE=all ./build.sh test-cov' + sh -c './build.sh clean \ + && go vet ./cmd/... ./internal/... \ + && ( golint ./cmd/... ; golint ./internal/... ) | egrep -v "comment on exported|should have comment" \ + && ./build.sh all \ + && STTRACE=all ./build.sh test-cov' ;; docker-test) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 6efc44a37..1ec59dd59 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -334,44 +334,44 @@ func restPostConfig(m *model.Model, w http.ResponseWriter, r *http.Request) { l.Warnln("decoding posted config:", err) http.Error(w, err.Error(), 500) return - } else { - if newCfg.GUI.Password != cfg.GUI().Password { - if newCfg.GUI.Password != "" { - hash, err := bcrypt.GenerateFromPassword([]byte(newCfg.GUI.Password), 0) - if err != nil { - l.Warnln("bcrypting password:", err) - http.Error(w, err.Error(), 500) - return - } else { - newCfg.GUI.Password = string(hash) - } - } - } - - // Start or stop usage reporting as appropriate - - if curAcc := cfg.Options().URAccepted; newCfg.Options.URAccepted > curAcc { - // UR was enabled - newCfg.Options.URAccepted = usageReportVersion - newCfg.Options.URUniqueID = randomString(8) - err := sendUsageReport(m) - if err != nil { - l.Infoln("Usage report:", err) - } - go usageReportingLoop(m) - } else if newCfg.Options.URAccepted < curAcc { - // UR was disabled - newCfg.Options.URAccepted = -1 - newCfg.Options.URUniqueID = "" - stopUsageReporting() - } - - // Activate and save - - configInSync = !config.ChangeRequiresRestart(cfg.Raw(), newCfg) - cfg.Replace(newCfg) - cfg.Save() } + + if newCfg.GUI.Password != cfg.GUI().Password { + if newCfg.GUI.Password != "" { + hash, err := bcrypt.GenerateFromPassword([]byte(newCfg.GUI.Password), 0) + if err != nil { + l.Warnln("bcrypting password:", err) + http.Error(w, err.Error(), 500) + return + } + + newCfg.GUI.Password = string(hash) + } + } + + // Start or stop usage reporting as appropriate + + if curAcc := cfg.Options().URAccepted; newCfg.Options.URAccepted > curAcc { + // UR was enabled + newCfg.Options.URAccepted = usageReportVersion + newCfg.Options.URUniqueID = randomString(8) + err := sendUsageReport(m) + if err != nil { + l.Infoln("Usage report:", err) + } + go usageReportingLoop(m) + } else if newCfg.Options.URAccepted < curAcc { + // UR was disabled + newCfg.Options.URAccepted = -1 + newCfg.Options.URUniqueID = "" + stopUsageReporting() + } + + // Activate and save + + configInSync = !config.ChangeRequiresRestart(cfg.Raw(), newCfg) + cfg.Replace(newCfg) + cfg.Save() } func restGetConfigInSync(w http.ResponseWriter, r *http.Request) { @@ -598,7 +598,7 @@ func restPostUpgrade(w http.ResponseWriter, r *http.Request) { } if upgrade.CompareVersions(rel.Tag, Version) == 1 { - err = upgrade.UpgradeTo(rel) + err = upgrade.To(rel) if err != nil { l.Warnln("upgrading:", err) http.Error(w, err.Error(), 500) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 7dd259a05..dd648ed2f 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -102,10 +102,10 @@ func init() { } var ( - cfg *config.ConfigWrapper + cfg *config.Wrapper myID protocol.DeviceID confDir string - logFlags int = log.Ltime + logFlags = log.Ltime writeRateLimit *ratelimit.Bucket readRateLimit *ratelimit.Bucket stop = make(chan int) @@ -332,15 +332,14 @@ func main() { l.Fatalln("Cannot upgrade, database seems to be locked. Is another copy of Syncthing already running?") } - err = upgrade.UpgradeTo(rel) + err = upgrade.To(rel) if err != nil { l.Fatalln("Upgrade:", err) // exits 1 } l.Okf("Upgraded to %q", rel.Tag) - return - } else { - return } + + return } if reset { @@ -610,7 +609,7 @@ func syncthingMain() { os.Exit(code) } -func setupGUI(cfg *config.ConfigWrapper, m *model.Model) { +func setupGUI(cfg *config.Wrapper, m *model.Model) { opts := cfg.Options() guiCfg := overrideGUIConfig(cfg.GUI(), guiAddress, guiAuthentication, guiAPIKey) @@ -651,7 +650,7 @@ func setupGUI(cfg *config.ConfigWrapper, m *model.Model) { } } -func sanityCheckFolders(cfg *config.ConfigWrapper, m *model.Model) { +func sanityCheckFolders(cfg *config.Wrapper, m *model.Model) { nextFolder: for id, folder := range cfg.Folders() { if folder.Invalid != "" { @@ -756,7 +755,7 @@ func setupUPnP() { if len(igds) > 0 { // Configure the first discovered IGD only. This is a work-around until we have a better mechanism // for handling multiple IGDs, which will require changes to the global discovery service - igd = igds[0] + igd = &igds[0] externalPort = setupExternalPort(igd, port) if externalPort == 0 { @@ -804,7 +803,7 @@ func renewUPnP(port int) { if len(igds) > 0 { // Configure the first discovered IGD only. This is a work-around until we have a better mechanism // for handling multiple IGDs, which will require changes to the global discovery service - igd = igds[0] + igd = &igds[0] } else { if debugNet { l.Debugln("Failed to discover IGD during UPnP port mapping renewal.") @@ -1256,7 +1255,7 @@ func autoUpgrade() { } l.Infof("Automatic upgrade (current %q < latest %q)", Version, rel.Tag) - err = upgrade.UpgradeTo(rel) + err = upgrade.To(rel) if err != nil { l.Warnln("Automatic upgrade:", err) continue diff --git a/cmd/syncthing/random_test.go b/cmd/syncthing/random_test.go index a04b96e5f..5cff1ed8c 100644 --- a/cmd/syncthing/random_test.go +++ b/cmd/syncthing/random_test.go @@ -46,7 +46,7 @@ func TestRandomString(t *testing.T) { for _, l := range []int{0, 1, 2, 3, 4, 8, 42} { s := randomString(l) if len(s) != l { - t.Errorf("Incorrect length %d != %s", len(s), l) + t.Errorf("Incorrect length %d != %d", len(s), l) } } diff --git a/docker/Dockerfile b/docker/Dockerfile index 8f015f1db..db2bcd2a7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -51,6 +51,11 @@ RUN go get github.com/tools/godep \ && go get github.com/axw/gocov/gocov \ && go get github.com/AlekSi/gocov-xml +# Install tools "go vet" and "golint" + +RUN go get golang.org/x/tools/cmd/vet \ + && go get github.com/golang/lint/golint + # Build standard library for race RUN go install -race std diff --git a/internal/config/config.go b/internal/config/config.go index 07679f091..9a3299ef7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -92,13 +92,13 @@ func (f *FolderConfiguration) HasMarker() bool { return true } -func (r *FolderConfiguration) DeviceIDs() []protocol.DeviceID { - if r.deviceIDs == nil { - for _, n := range r.Devices { - r.deviceIDs = append(r.deviceIDs, n.DeviceID) +func (f *FolderConfiguration) DeviceIDs() []protocol.DeviceID { + if f.deviceIDs == nil { + for _, n := range f.Devices { + f.deviceIDs = append(f.deviceIDs, n.DeviceID) } } - return r.deviceIDs + return f.deviceIDs } type VersioningConfiguration struct { diff --git a/internal/config/wrapper.go b/internal/config/wrapper.go index 66d17d7b5..ae01f1e0f 100644 --- a/internal/config/wrapper.go +++ b/internal/config/wrapper.go @@ -42,7 +42,7 @@ func (fn HandlerFunc) Changed(cfg Configuration) error { // A wrapper around a Configuration that manages loads, saves and published // notifications of changes to registered Handlers -type ConfigWrapper struct { +type Wrapper struct { cfg Configuration path string @@ -57,8 +57,8 @@ type ConfigWrapper struct { // Wrap wraps an existing Configuration structure and ties it to a file on // disk. -func Wrap(path string, cfg Configuration) *ConfigWrapper { - w := &ConfigWrapper{cfg: cfg, path: path} +func Wrap(path string, cfg Configuration) *Wrapper { + w := &Wrapper{cfg: cfg, path: path} w.replaces = make(chan Configuration) go w.Serve() return w @@ -66,7 +66,7 @@ func Wrap(path string, cfg Configuration) *ConfigWrapper { // Load loads an existing file on disk and returns a new configuration // wrapper. -func Load(path string, myID protocol.DeviceID) (*ConfigWrapper, error) { +func Load(path string, myID protocol.DeviceID) (*Wrapper, error) { fd, err := os.Open(path) if err != nil { return nil, err @@ -84,7 +84,7 @@ func Load(path string, myID protocol.DeviceID) (*ConfigWrapper, error) { // Serve handles configuration replace events and calls any interested // handlers. It is started automatically by Wrap() and Load() and should not // be run manually. -func (w *ConfigWrapper) Serve() { +func (w *Wrapper) Serve() { for cfg := range w.replaces { w.sMut.Lock() subs := w.subs @@ -97,25 +97,25 @@ func (w *ConfigWrapper) Serve() { // Stop stops the Serve() loop. Set and Replace operations will panic after a // Stop. -func (w *ConfigWrapper) Stop() { +func (w *Wrapper) Stop() { close(w.replaces) } // Subscribe registers the given handler to be called on any future // configuration changes. -func (w *ConfigWrapper) Subscribe(h Handler) { +func (w *Wrapper) Subscribe(h Handler) { w.sMut.Lock() w.subs = append(w.subs, h) w.sMut.Unlock() } // Raw returns the currently wrapped Configuration object. -func (w *ConfigWrapper) Raw() Configuration { +func (w *Wrapper) Raw() Configuration { return w.cfg } // Replace swaps the current configuration object for the given one. -func (w *ConfigWrapper) Replace(cfg Configuration) { +func (w *Wrapper) Replace(cfg Configuration) { w.mut.Lock() defer w.mut.Unlock() @@ -127,7 +127,7 @@ func (w *ConfigWrapper) Replace(cfg Configuration) { // Devices returns a map of devices. Device structures should not be changed, // other than for the purpose of updating via SetDevice(). -func (w *ConfigWrapper) Devices() map[protocol.DeviceID]DeviceConfiguration { +func (w *Wrapper) Devices() map[protocol.DeviceID]DeviceConfiguration { w.mut.Lock() defer w.mut.Unlock() if w.deviceMap == nil { @@ -141,7 +141,7 @@ func (w *ConfigWrapper) Devices() map[protocol.DeviceID]DeviceConfiguration { // SetDevice adds a new device to the configuration, or overwrites an existing // device with the same ID. -func (w *ConfigWrapper) SetDevice(dev DeviceConfiguration) { +func (w *Wrapper) SetDevice(dev DeviceConfiguration) { w.mut.Lock() defer w.mut.Unlock() @@ -161,7 +161,7 @@ func (w *ConfigWrapper) SetDevice(dev DeviceConfiguration) { // Devices returns a map of folders. Folder structures should not be changed, // other than for the purpose of updating via SetFolder(). -func (w *ConfigWrapper) Folders() map[string]FolderConfiguration { +func (w *Wrapper) Folders() map[string]FolderConfiguration { w.mut.Lock() defer w.mut.Unlock() if w.folderMap == nil { @@ -181,7 +181,7 @@ func (w *ConfigWrapper) Folders() map[string]FolderConfiguration { // SetFolder adds a new folder to the configuration, or overwrites an existing // folder with the same ID. -func (w *ConfigWrapper) SetFolder(fld FolderConfiguration) { +func (w *Wrapper) SetFolder(fld FolderConfiguration) { w.mut.Lock() defer w.mut.Unlock() @@ -200,14 +200,14 @@ func (w *ConfigWrapper) SetFolder(fld FolderConfiguration) { } // Options returns the current options configuration object. -func (w *ConfigWrapper) Options() OptionsConfiguration { +func (w *Wrapper) Options() OptionsConfiguration { w.mut.Lock() defer w.mut.Unlock() return w.cfg.Options } // SetOptions replaces the current options configuration object. -func (w *ConfigWrapper) SetOptions(opts OptionsConfiguration) { +func (w *Wrapper) SetOptions(opts OptionsConfiguration) { w.mut.Lock() defer w.mut.Unlock() w.cfg.Options = opts @@ -215,14 +215,14 @@ func (w *ConfigWrapper) SetOptions(opts OptionsConfiguration) { } // GUI returns the current GUI configuration object. -func (w *ConfigWrapper) GUI() GUIConfiguration { +func (w *Wrapper) GUI() GUIConfiguration { w.mut.Lock() defer w.mut.Unlock() return w.cfg.GUI } // SetGUI replaces the current GUI configuration object. -func (w *ConfigWrapper) SetGUI(gui GUIConfiguration) { +func (w *Wrapper) SetGUI(gui GUIConfiguration) { w.mut.Lock() defer w.mut.Unlock() w.cfg.GUI = gui @@ -230,7 +230,7 @@ func (w *ConfigWrapper) SetGUI(gui GUIConfiguration) { } // InvalidateFolder sets the invalid marker on the given folder. -func (w *ConfigWrapper) InvalidateFolder(id string, err string) { +func (w *Wrapper) InvalidateFolder(id string, err string) { w.mut.Lock() defer w.mut.Unlock() @@ -246,7 +246,7 @@ func (w *ConfigWrapper) InvalidateFolder(id string, err string) { } // Save writes the configuration to disk, and generates a ConfigSaved event. -func (w *ConfigWrapper) Save() error { +func (w *Wrapper) Save() error { fd, err := ioutil.TempFile(filepath.Dir(w.path), "cfg") if err != nil { return err diff --git a/internal/events/events.go b/internal/events/events.go index 8dd845d38..7fce142ee 100644 --- a/internal/events/events.go +++ b/internal/events/events.go @@ -86,7 +86,7 @@ const BufferSize = 64 type Logger struct { subs map[int]*Subscription - nextId int + nextID int mutex sync.Mutex } @@ -120,15 +120,15 @@ func NewLogger() *Logger { func (l *Logger) Log(t EventType, data interface{}) { l.mutex.Lock() if debug { - dl.Debugln("log", l.nextId, t.String(), data) + dl.Debugln("log", l.nextID, t.String(), data) } e := Event{ - ID: l.nextId, + ID: l.nextID, Time: time.Now(), Type: t, Data: data, } - l.nextId++ + l.nextID++ for _, s := range l.subs { if s.mask&t != 0 { select { @@ -148,10 +148,10 @@ func (l *Logger) Subscribe(mask EventType) *Subscription { } s := &Subscription{ mask: mask, - id: l.nextId, + id: l.nextID, events: make(chan Event, BufferSize), } - l.nextId++ + l.nextID++ l.subs[s.id] = s l.mutex.Unlock() return s diff --git a/internal/files/blockmap.go b/internal/files/blockmap.go index 618f44f4e..147a1d100 100644 --- a/internal/files/blockmap.go +++ b/internal/files/blockmap.go @@ -126,7 +126,7 @@ type BlockFinder struct { mut sync.RWMutex } -func NewBlockFinder(db *leveldb.DB, cfg *config.ConfigWrapper) *BlockFinder { +func NewBlockFinder(db *leveldb.DB, cfg *config.Wrapper) *BlockFinder { if blockFinder != nil { return blockFinder } diff --git a/internal/ignore/cache_test.go b/internal/ignore/cache_test.go index 155e22c35..27628520d 100644 --- a/internal/ignore/cache_test.go +++ b/internal/ignore/cache_test.go @@ -25,7 +25,7 @@ func TestCache(t *testing.T) { res, ok := c.get("nonexistent") if res != false || ok != false { - t.Error("res %v, ok %v for nonexistent item", res, ok) + t.Errorf("res %v, ok %v for nonexistent item", res, ok) } // Set and check some items diff --git a/internal/ignore/ignore.go b/internal/ignore/ignore.go index 48d2ede75..e74c7ad21 100644 --- a/internal/ignore/ignore.go +++ b/internal/ignore/ignore.go @@ -169,9 +169,8 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) (*M includes, err := loadIgnoreFile(includeFile, seen) if err != nil { return err - } else { - exps.patterns = append(exps.patterns, includes.patterns...) } + exps.patterns = append(exps.patterns, includes.patterns...) } else { // Path name or pattern, add it so it matches files both in // current directory and subdirs. diff --git a/internal/model/deviceactivity.go b/internal/model/deviceactivity.go index 19d84400f..2c8fd5ad1 100644 --- a/internal/model/deviceactivity.go +++ b/internal/model/deviceactivity.go @@ -37,7 +37,7 @@ func newDeviceActivity() *deviceActivity { func (m *deviceActivity) leastBusy(availability []protocol.DeviceID) protocol.DeviceID { m.mut.Lock() - var low int = 2<<30 - 1 + low := 2<<30 - 1 var selected protocol.DeviceID for _, device := range availability { if usage := m.act[device]; usage < low { diff --git a/internal/model/deviceactivity_test.go b/internal/model/deviceactivity_test.go index 7d4ed2c92..a4f672d1c 100644 --- a/internal/model/deviceactivity_test.go +++ b/internal/model/deviceactivity_test.go @@ -22,9 +22,9 @@ import ( ) func TestDeviceActivity(t *testing.T) { - n0 := protocol.DeviceID{1, 2, 3, 4} - n1 := protocol.DeviceID{5, 6, 7, 8} - n2 := protocol.DeviceID{9, 10, 11, 12} + n0 := protocol.DeviceID([32]byte{1, 2, 3, 4}) + n1 := protocol.DeviceID([32]byte{5, 6, 7, 8}) + n2 := protocol.DeviceID([32]byte{9, 10, 11, 12}) devices := []protocol.DeviceID{n0, n1, n2} na := newDeviceActivity() diff --git a/internal/model/model.go b/internal/model/model.go index ab1879ad5..d6b589425 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -82,7 +82,7 @@ type service interface { } type Model struct { - cfg *config.ConfigWrapper + cfg *config.Wrapper db *leveldb.DB finder *files.BlockFinder progressEmitter *ProgressEmitter @@ -123,7 +123,7 @@ var ( // NewModel creates and starts a new model. The model starts in read-only mode, // where it sends index information to connected peers and responds to requests // for file data without altering the local folder in any way. -func NewModel(cfg *config.ConfigWrapper, deviceName, clientName, clientVersion string, db *leveldb.DB) *Model { +func NewModel(cfg *config.Wrapper, deviceName, clientName, clientVersion string, db *leveldb.DB) *Model { m := &Model{ cfg: cfg, db: db, @@ -862,11 +862,11 @@ func (m *Model) deviceStatRef(deviceID protocol.DeviceID) *stats.DeviceStatistic if sr, ok := m.deviceStatRefs[deviceID]; ok { return sr - } else { - sr = stats.NewDeviceStatisticsReference(m.db, deviceID) - m.deviceStatRefs[deviceID] = sr - return sr } + + sr := stats.NewDeviceStatisticsReference(m.db, deviceID) + m.deviceStatRefs[deviceID] = sr + return sr } func (m *Model) deviceWasSeen(deviceID protocol.DeviceID) { diff --git a/internal/model/progressemitter.go b/internal/model/progressemitter.go index 203b0b1f1..60df30588 100755 --- a/internal/model/progressemitter.go +++ b/internal/model/progressemitter.go @@ -38,7 +38,7 @@ type ProgressEmitter struct { // Creates a new progress emitter which emits DownloadProgress events every // interval. -func NewProgressEmitter(cfg *config.ConfigWrapper) *ProgressEmitter { +func NewProgressEmitter(cfg *config.Wrapper) *ProgressEmitter { t := &ProgressEmitter{ stop: make(chan struct{}), registry: make(map[string]*sharedPullerState), diff --git a/internal/scanner/walk.go b/internal/scanner/walk.go index 403958613..d0a1d4819 100644 --- a/internal/scanner/walk.go +++ b/internal/scanner/walk.go @@ -201,7 +201,7 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun } } - var flags uint32 = protocol.FlagDirectory + flags := uint32(protocol.FlagDirectory) if w.IgnorePerms { flags |= protocol.FlagNoPermBits | 0777 } else { diff --git a/internal/scanner/walk_test.go b/internal/scanner/walk_test.go index 13cc45c7c..859b81d6b 100644 --- a/internal/scanner/walk_test.go +++ b/internal/scanner/walk_test.go @@ -190,16 +190,16 @@ func TestVerify(t *testing.T) { type fileList []protocol.FileInfo -func (f fileList) Len() int { - return len(f) +func (l fileList) Len() int { + return len(l) } -func (f fileList) Less(a, b int) bool { - return f[a].Name < f[b].Name +func (l fileList) Less(a, b int) bool { + return l[a].Name < l[b].Name } -func (f fileList) Swap(a, b int) { - f[a], f[b] = f[b], f[a] +func (l fileList) Swap(a, b int) { + l[a], l[b] = l[b], l[a] } func (l fileList) testfiles() testfileList { diff --git a/internal/upgrade/upgrade_common.go b/internal/upgrade/upgrade_common.go index 6cc6d9582..5ad69754a 100644 --- a/internal/upgrade/upgrade_common.go +++ b/internal/upgrade/upgrade_common.go @@ -48,7 +48,7 @@ func init() { } // A wrapper around actual implementations -func UpgradeTo(rel Release) error { +func To(rel Release) error { select { case <-upgradeUnlocked: path, err := osext.Executable() diff --git a/internal/upgrade/upgrade_supported.go b/internal/upgrade/upgrade_supported.go index dc2ec719d..4eec6f2d1 100644 --- a/internal/upgrade/upgrade_supported.go +++ b/internal/upgrade/upgrade_supported.go @@ -86,15 +86,15 @@ func LatestRelease(prerelease bool) (Release, error) { if prerelease { // We are a beta version. Use the latest. return rels[0], nil - } else { - // We are a regular release. Only consider non-prerelease versions for upgrade. - for _, rel := range rels { - if !rel.Prerelease { - return rel, nil - } - } - return Release{}, ErrVersionUnknown } + + // We are a regular release. Only consider non-prerelease versions for upgrade. + for _, rel := range rels { + if !rel.Prerelease { + return rel, nil + } + } + return Release{}, ErrVersionUnknown } func readTarGZ(url string, dir string) (string, error) { diff --git a/internal/upnp/upnp.go b/internal/upnp/upnp.go index c1d9786f9..8bb0367be 100644 --- a/internal/upnp/upnp.go +++ b/internal/upnp/upnp.go @@ -101,8 +101,8 @@ type upnpRoot struct { // Discover discovers UPnP InternetGatewayDevices. // The order in which the devices appear in the result list is not deterministic. -func Discover() []*IGD { - result := make([]*IGD, 0) +func Discover() []IGD { + var result []IGD l.Infoln("Starting UPnP discovery...") timeout := 3 @@ -137,7 +137,7 @@ func Discover() []*IGD { // Search for UPnP InternetGatewayDevices for seconds, ignoring responses from any devices listed in knownDevices. // The order in which the devices appear in the result list is not deterministic -func discover(deviceType string, timeout int, knownDevices []*IGD) []*IGD { +func discover(deviceType string, timeout int, knownDevices []IGD) []IGD { ssdp := &net.UDPAddr{IP: []byte{239, 255, 255, 250}, Port: 1900} tpl := `M-SEARCH * HTTP/1.1 @@ -155,8 +155,8 @@ Mx: %d l.Debugln("Starting discovery of device type " + deviceType + "...") } - results := make([]*IGD, 0) - resultChannel := make(chan *IGD, 8) + var results []IGD + resultChannel := make(chan IGD, 8) socket, err := net.ListenUDP("udp4", &net.UDPAddr{}) if err != nil { @@ -231,7 +231,7 @@ Mx: %d return results } -func handleSearchResponse(deviceType string, knownDevices []*IGD, resp []byte, length int, resultChannel chan<- *IGD, resultWaitGroup *sync.WaitGroup) { +func handleSearchResponse(deviceType string, knownDevices []IGD, resp []byte, length int, resultChannel chan<- IGD, resultWaitGroup *sync.WaitGroup) { defer resultWaitGroup.Done() // Signal when we've finished processing if debug { @@ -321,7 +321,7 @@ func handleSearchResponse(deviceType string, knownDevices []*IGD, resp []byte, l return } - igd := &IGD{ + igd := IGD{ uuid: deviceUUID, friendlyName: upnpRoot.Device.FriendlyName, url: deviceDescriptionURL, @@ -352,7 +352,7 @@ func localIP(url *url.URL) (string, error) { } func getChildDevices(d upnpDevice, deviceType string) []upnpDevice { - result := make([]upnpDevice, 0) + var result []upnpDevice for _, dev := range d.Devices { if dev.DeviceType == deviceType { result = append(result, dev) @@ -362,7 +362,7 @@ func getChildDevices(d upnpDevice, deviceType string) []upnpDevice { } func getChildServices(d upnpDevice, serviceType string) []upnpService { - result := make([]upnpService, 0) + var result []upnpService for _, svc := range d.Services { if svc.ServiceType == serviceType { result = append(result, svc) @@ -372,7 +372,7 @@ func getChildServices(d upnpDevice, serviceType string) []upnpService { } func getServiceDescriptions(rootURL string, device upnpDevice) ([]IGDService, error) { - result := make([]IGDService, 0) + var result []IGDService if device.DeviceType == "urn:schemas-upnp-org:device:InternetGatewayDevice:1" { descriptions := getIGDServices(rootURL, device, @@ -400,7 +400,7 @@ func getServiceDescriptions(rootURL string, device upnpDevice) ([]IGDService, er } func getIGDServices(rootURL string, device upnpDevice, wanDeviceURN string, wanConnectionURN string, serviceURNs []string) []IGDService { - result := make([]IGDService, 0) + var result []IGDService devices := getChildDevices(device, wanDeviceURN) diff --git a/internal/upnp/upnp_test.go b/internal/upnp/upnp_test.go index 2023b708f..e7fc6b962 100644 --- a/internal/upnp/upnp_test.go +++ b/internal/upnp/upnp_test.go @@ -21,7 +21,7 @@ import ( ) func TestExternalIPParsing(t *testing.T) { - soap_response := + soapResponse := []byte(` @@ -31,7 +31,7 @@ func TestExternalIPParsing(t *testing.T) { `) envelope := &soapGetExternalIPAddressResponseEnvelope{} - err := xml.Unmarshal(soap_response, envelope) + err := xml.Unmarshal(soapResponse, envelope) if err != nil { t.Error(err) } diff --git a/internal/versioner/simple.go b/internal/versioner/simple.go index e51575fe5..9be3434a9 100644 --- a/internal/versioner/simple.go +++ b/internal/versioner/simple.go @@ -62,9 +62,8 @@ func (v Simple) Archive(filePath string) error { l.Debugln("not archiving nonexistent file", filePath) } return nil - } else { - return err } + return err } versionsDir := filepath.Join(v.folderPath, ".stversions") diff --git a/internal/versioner/staggered.go b/internal/versioner/staggered.go index 4ae216066..8330bd6f4 100644 --- a/internal/versioner/staggered.go +++ b/internal/versioner/staggered.go @@ -294,9 +294,8 @@ func (v Staggered) Archive(filePath string) error { l.Debugln("not archiving nonexistent file", filePath) } return nil - } else { - return err } + return err } if _, err := os.Stat(v.versionsPath); err != nil {