diff --git a/.circleci/config.yml b/.circleci/config.yml index f569234..ba6e9e5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,19 @@ # Check https://circleci.com/docs/2.0/language-go/ for more details version: 2.1 jobs: + lint: + docker: + - image: circleci/golang:1.14.1 + + steps: + - checkout + + - run: + name: Run golangci-lint + command: | + go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.31.0 + golangci-lint run + build-linux: docker: - image: circleci/golang:1.14.1 @@ -202,7 +215,11 @@ workflows: build: jobs: - build-linux + requires: + - lint - build-other + requires: + - lint - upload: requires: - build-linux diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..c35edee --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,10 @@ +run: + build-tags: + - lint + issues-exit-code: 0 # TODO: change this to 1 when we want it to fail builds + skip-dirs: + - contrib/ + - misc/ +linters: + disable: + - gocyclo \ No newline at end of file diff --git a/cmd/yggdrasil/main.go b/cmd/yggdrasil/main.go index 7184423..19921ab 100644 --- a/cmd/yggdrasil/main.go +++ b/cmd/yggdrasil/main.go @@ -138,7 +138,7 @@ func run_yggdrasil() { getNodeID := func() *crypto.NodeID { if pubkey, err := hex.DecodeString(yggConfig.EncryptionPublicKey); err == nil { var box crypto.BoxPubKey - copy(box[:], pubkey[:]) + copy(box[:], pubkey) return crypto.GetNodeID(&box) } return nil @@ -272,9 +272,9 @@ func run_yggdrasil() { // deferred Stop function above will run which will shut down TUN/TAP. for { select { - case _ = <-c: + case <-c: goto exit - case _ = <-r: + case <-r: if *useconffile != "" { yggConfig, popConfig = popura.LoadConfig(useconf, useconffile, normaliseconf) logger.Infoln("Reloading configuration from", *useconffile) diff --git a/cmd/yggdrasilctl/main.go b/cmd/yggdrasilctl/main.go index 697a3fa..38d935a 100644 --- a/cmd/yggdrasilctl/main.go +++ b/cmd/yggdrasilctl/main.go @@ -78,8 +78,8 @@ func run() int { if *server == endpoint { if config, err := ioutil.ReadFile(defaults.GetDefaults().DefaultConfigFile); err == nil { - if bytes.Compare(config[0:2], []byte{0xFF, 0xFE}) == 0 || - bytes.Compare(config[0:2], []byte{0xFE, 0xFF}) == 0 { + if bytes.Equal(config[0:2], []byte{0xFF, 0xFE}) || + bytes.Equal(config[0:2], []byte{0xFE, 0xFF}) { utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM) decoder := utf.NewDecoder() config, err = decoder.Bytes(config) diff --git a/go.mod b/go.mod index d4a6173..4725162 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/fatih/color v1.9.0 // indirect github.com/gologme/log v1.2.0 github.com/hashicorp/go-syslog v1.0.0 - github.com/hjson/hjson-go v3.0.1+incompatible + github.com/hjson/hjson-go v3.0.2-0.20200316202735-d5d0e8b0617d+incompatible github.com/kardianos/minwinsvc v0.0.0-20151122163309-cad6b2b879b0 github.com/mattn/go-colorable v0.1.6 // indirect github.com/mattn/go-runewidth v0.0.9 // indirect @@ -16,7 +16,7 @@ require ( github.com/mitchellh/mapstructure v1.3.0 github.com/vishvananda/netlink v1.1.0 github.com/vishvananda/netns v0.0.0-20200520041808-52d707b772fe // indirect - github.com/yggdrasil-network/yggdrasil-go v0.3.14 + github.com/yggdrasil-network/yggdrasil-go v0.3.15 github.com/zhoreeq/meshname v0.1.0 golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect golang.org/x/net v0.0.0-20200602114024-627f9648deb9 diff --git a/go.sum b/go.sum index 91786ed..3c41f6a 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,8 @@ github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdv github.com/hjson/hjson-go v3.0.1-0.20190209023717-9147687966d9+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio= github.com/hjson/hjson-go v3.0.1+incompatible h1:JwOXblcMiBbiWue7iPkoFK9oXSnW8n+qXh/0Fio6TCo= github.com/hjson/hjson-go v3.0.1+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio= +github.com/hjson/hjson-go v3.0.2-0.20200316202735-d5d0e8b0617d+incompatible h1:v6BPcb9q9U6JDVsuizxBr/piVB/2Y1Q5GWoBybvZVWI= +github.com/hjson/hjson-go v3.0.2-0.20200316202735-d5d0e8b0617d+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio= github.com/kardianos/minwinsvc v0.0.0-20151122163309-cad6b2b879b0 h1:YnZmFjg0Nvk8851WTVWlqMC1ecJH07Ctz+Ezxx4u54g= github.com/kardianos/minwinsvc v0.0.0-20151122163309-cad6b2b879b0/go.mod h1:rUi0/YffDo1oXBOGn1KRq7Fr07LX48XEBecQnmwjsAo= github.com/lxn/walk v0.0.0-20191128110447-55ccb3a9f5c1/go.mod h1:E23UucZGqpuUANJooIbHWCufXvOcT6E7Stq81gU+CSQ= @@ -57,8 +59,11 @@ github.com/vishvananda/netns v0.0.0-20190625233234-7109fa855b0f/go.mod h1:ZjcWmF github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU= github.com/vishvananda/netns v0.0.0-20200520041808-52d707b772fe h1:mjAZxE1nh8yvuwhGHpdDqdhtNu2dgbpk93TwoXuk5so= github.com/vishvananda/netns v0.0.0-20200520041808-52d707b772fe/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= +github.com/yggdrasil-network/yggdrasil-extras v0.0.0-20200525205615-6c8a4a2e8855/go.mod h1:xQdsh08Io6nV4WRnOVTe6gI8/2iTvfLDQ0CYa5aMt+I= github.com/yggdrasil-network/yggdrasil-go v0.3.14 h1:vWzYzCQxOruS+J5FkLfXOS0JhCJx1yI9Erj/h2wfZ/E= github.com/yggdrasil-network/yggdrasil-go v0.3.14/go.mod h1:rkQzLzVHlFdzsEMG+bDdTI+KeWPCZq1HpXRFzwinf6M= +github.com/yggdrasil-network/yggdrasil-go v0.3.15 h1:os+HOx1nyxEv9awTIkliMPgIFljywVOZDroFWz2C2B0= +github.com/yggdrasil-network/yggdrasil-go v0.3.15/go.mod h1:d+Nz6SPeG6kmeSPFL0cvfWfgwEql75fUnZiAONgvyBE= github.com/zhoreeq/meshname v0.0.0-20200517140506-5c5e93874284 h1:BziJ6xfXSA7u8Jm7DlIYRrpUxbbtE7o9x3OgxDY2lUQ= github.com/zhoreeq/meshname v0.0.0-20200517140506-5c5e93874284/go.mod h1:3I8MpFZ304bAYiD+e+ovlMDDZat8aKyUlqllUok4qm0= github.com/zhoreeq/meshname v0.0.0-20200519200412-cad772d30578 h1:xmEYsm95dzBKWEYTmDdGJer1geUd52WctSXTW84U9ns= diff --git a/src/popura/config.go b/src/popura/config.go index eb2e096..64f3ef5 100644 --- a/src/popura/config.go +++ b/src/popura/config.go @@ -115,8 +115,8 @@ func LoadConfig(useconf *bool, useconffile *string, normaliseconf *bool) (*confi // throwing everywhere when it's converting things into UTF-16 for the hell // of it - remove it and decode back down into UTF-8. This is necessary // because hjson doesn't know what to do with UTF-16 and will panic - if bytes.Compare(conf[0:2], []byte{0xFF, 0xFE}) == 0 || - bytes.Compare(conf[0:2], []byte{0xFE, 0xFF}) == 0 { + if bytes.Equal(conf[0:2], []byte{0xFF, 0xFE}) || + bytes.Equal(conf[0:2], []byte{0xFE, 0xFF}) { utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM) decoder := utf.NewDecoder() conf, err = decoder.Bytes(conf)