diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..b90a29f --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,27 @@ +--- +name: golangci-lint +on: + push: + paths: + - "go.sum" + - "go.mod" + - "**.go" + - ".github/workflows/golangci-lint.yml" + - ".golangci.yml" + pull_request: + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: install Go + uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0 + with: + go-version: 1.21.x + - name: Lint + uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 + with: + version: v1.54.2 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..295167c --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,18 @@ +--- +linters: + enable: + - gofmt + - misspell + - revive + +linters-settings: + misspell: + ignore-words: + # Incorrect spelling used in CacheInfo struct. + - Prefered + revive: + rules: + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter + - name: unused-parameter + severity: warning + disabled: true diff --git a/link.go b/link.go index 89b9d23..751c099 100644 --- a/link.go +++ b/link.go @@ -165,7 +165,7 @@ func (l *LinkService) Get(index uint32) (LinkMessage, error) { // RTM_SETLINK because: // - using RTM_SETLINK is actually an old rtnetlink API, not supporting most // attributes common today -// - using RTM_NEWLINK is the prefered way to create AND update links +// - using RTM_NEWLINK is the preferred way to create AND update links // - RTM_NEWLINK is backward compatible to RTM_SETLINK func (l *LinkService) Set(req *LinkMessage) error { flags := netlink.Request | netlink.Acknowledge diff --git a/rtnl/addr.go b/rtnl/addr.go index e5df848..29f921d 100644 --- a/rtnl/addr.go +++ b/rtnl/addr.go @@ -12,7 +12,6 @@ import ( // // iface, _ := net.InterfaceByName("lo") // conn.AddrAdd(iface, rtnl.MustParseAddr("127.0.0.1/8")) -// func (c *Conn) AddrAdd(ifc *net.Interface, addr *net.IPNet) error { af, err := addrFamily(addr.IP) if err != nil { @@ -43,7 +42,6 @@ func (c *Conn) AddrAdd(ifc *net.Interface, addr *net.IPNet) error { // // iface, _ := net.InterfaceByName("lo") // conn.AddrDel(iface, rtnl.MustParseAddr("127.0.0.1/8")) -// func (c *Conn) AddrDel(ifc *net.Interface, addr *net.IPNet) error { af, err := addrFamily(addr.IP) if err != nil { @@ -79,7 +77,6 @@ func (c *Conn) AddrDel(ifc *net.Interface, addr *net.IPNet) error { // To retrieve all addresses configured for the system, run: // // conn.Addrs(nil, 0) -// func (c *Conn) Addrs(ifc *net.Interface, family int) (out []*net.IPNet, err error) { rx, err := c.Conn.Address.List() if err != nil { @@ -136,7 +133,6 @@ func ParseAddr(s string) (*net.IPNet, error) { // // iface, _ := net.InterfaceByName("enp2s0") // conn.AddrDel(iface, rtnl.MustParseAddr("10.1.1.1/24")) -// func MustParseAddr(s string) *net.IPNet { n, err := ParseAddr(s) if err != nil { diff --git a/rtnl/conn.go b/rtnl/conn.go index 720472c..60d0ab4 100644 --- a/rtnl/conn.go +++ b/rtnl/conn.go @@ -12,13 +12,13 @@ type Conn struct { } // Dial the netlink socket. Establishes a new connection. The typical initialisation is: -// conn, err := rtnl.Dial(nil) +// +// conn, err := rtnl.Dial(nil) // if err != nil { // log.Fatal("can't establish netlink connection: ", err) // } // defer conn.Close() // // use conn for your calls -// func Dial(cfg *netlink.Config) (*Conn, error) { conn, err := rtnetlink.Dial(cfg) if err != nil { diff --git a/rtnl/route.go b/rtnl/route.go index c5f7109..e785141 100644 --- a/rtnl/route.go +++ b/rtnl/route.go @@ -64,7 +64,7 @@ func genRouteMessage(ifc *net.Interface, dst net.IPNet, gw net.IP, options ...Ro return tx, nil } -// RouteAdd adds infomation about a network route. +// RouteAdd adds information about a network route. func (c *Conn) RouteAdd(ifc *net.Interface, dst net.IPNet, gw net.IP, options ...RouteOption) (err error) { rm, err := genRouteMessage(ifc, dst, gw, options...) if err != nil {