From 1492738c9e05ad77accea0dbbdd275bc98d7d4b8 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 27 Sep 2020 14:28:25 +0100 Subject: [PATCH] golangci-lint in CI (#733) * golangci-lint in CI * Put CI in own job * Run verify job * Use go get * Fix typo * Name lint instead of verify * Read the config * Use debug tag * Tweaks --- .circleci/config.yml | 26 ++++++++- .golangci.yml | 10 ++++ contrib/config/yggdrasilconf.go | 97 --------------------------------- misc/sim/treesim.go | 28 ++++++---- 4 files changed, 49 insertions(+), 112 deletions(-) create mode 100644 .golangci.yml delete mode 100644 contrib/config/yggdrasilconf.go diff --git a/.circleci/config.yml b/.circleci/config.yml index 3f555df5..c1c8cf4a 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 @@ -201,9 +214,16 @@ workflows: version: 2.1 build: jobs: - - build-linux - - build-macos - - build-other + - lint + - build-linux: + requires: + - lint + - build-macos: + requires: + - lint + - build-other: + requires: + - lint - upload: requires: - build-linux diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..c35edee4 --- /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/contrib/config/yggdrasilconf.go b/contrib/config/yggdrasilconf.go deleted file mode 100644 index ad55e163..00000000 --- a/contrib/config/yggdrasilconf.go +++ /dev/null @@ -1,97 +0,0 @@ -package main - -/* -This is a small utility that is designed to accompany the vyatta-yggdrasil -package. It takes a HJSON configuration file, makes changes to it based on -the command line arguments, and then spits out an updated file. -*/ - -import ( - "bytes" - "encoding/json" - "flag" - "fmt" - "io/ioutil" - "strconv" - - "github.com/hjson/hjson-go" - "golang.org/x/text/encoding/unicode" - - "github.com/yggdrasil-network/yggdrasil-go/src/config" -) - -type nodeConfig = config.NodeConfig - -func main() { - useconffile := flag.String("useconffile", "/etc/yggdrasil.conf", "update config at specified file path") - flag.Parse() - cfg := nodeConfig{} - var config []byte - var err error - config, err = ioutil.ReadFile(*useconffile) - if err != nil { - panic(err) - } - if bytes.Compare(config[0:2], []byte{0xFF, 0xFE}) == 0 || - bytes.Compare(config[0:2], []byte{0xFE, 0xFF}) == 0 { - utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM) - decoder := utf.NewDecoder() - config, err = decoder.Bytes(config) - if err != nil { - panic(err) - } - } - var dat map[string]interface{} - if err := hjson.Unmarshal(config, &dat); err != nil { - panic(err) - } - confJson, err := json.Marshal(dat) - if err != nil { - panic(err) - } - json.Unmarshal(confJson, &cfg) - switch flag.Arg(0) { - case "setMTU": - cfg.IfMTU, err = strconv.Atoi(flag.Arg(1)) - if err != nil { - cfg.IfMTU = 1280 - } - if mtu, _ := strconv.Atoi(flag.Arg(1)); mtu < 1280 { - cfg.IfMTU = 1280 - } - case "setIfName": - cfg.IfName = flag.Arg(1) - case "setListen": - cfg.Listen = flag.Arg(1) - case "setAdminListen": - cfg.AdminListen = flag.Arg(1) - case "setIfTapMode": - if flag.Arg(1) == "true" { - cfg.IfTAPMode = true - } else { - cfg.IfTAPMode = false - } - case "addPeer": - found := false - for _, v := range cfg.Peers { - if v == flag.Arg(1) { - found = true - } - } - if !found { - cfg.Peers = append(cfg.Peers, flag.Arg(1)) - } - case "removePeer": - for k, v := range cfg.Peers { - if v == flag.Arg(1) { - cfg.Peers = append(cfg.Peers[:k], cfg.Peers[k+1:]...) - } - } - } - bs, err := hjson.Marshal(cfg) - if err != nil { - panic(err) - } - fmt.Println(string(bs)) - return -} diff --git a/misc/sim/treesim.go b/misc/sim/treesim.go index 2b155151..22cf881f 100644 --- a/misc/sim/treesim.go +++ b/misc/sim/treesim.go @@ -1,20 +1,24 @@ +// +build !lint + package main -import "fmt" -import "bufio" -import "os" -import "strings" -import "strconv" -import "time" +import ( + "bufio" + "flag" + "fmt" + "os" + "runtime" + "runtime/pprof" + "strconv" + "strings" + "time" -import "runtime" -import "runtime/pprof" -import "flag" + "github.com/gologme/log" -import "github.com/gologme/log" + . "github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil" -import . "github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil" -import . "github.com/yggdrasil-network/yggdrasil-go/src/crypto" + . "github.com/yggdrasil-network/yggdrasil-go/src/crypto" +) ////////////////////////////////////////////////////////////////////////////////