netbox-community / go-netbox

The official Go API client for Netbox IPAM and DCIM service.
Other
192 stars 141 forks source link

Docs reference deprecated `go get`; Cannot install with go 1.19 #138

Closed vwbusguy closed 1 year ago

vwbusguy commented 1 year ago

In Go 1.19, go get has been deprecated for go install (Ref. https://go.dev/doc/go-get-install-deprecation), however this module doesn't seem to be compatible with the new go dependency fetcher method.

go doesn't fetch github.com/netbox-community/go-netbox/netbox/client from the import ( section given in examples with an error like:

dhcp-netbox.go:5:5: no required module provides package github.com/netbox-community/go-netbox/netbox/client: go.mod file not found in current directory or any parent directory; see 'go help modules'

And replacing the go get with go install @latest gives an error that the package does not match:

go install github.com/netbox-community/go-netbox@latest
go: github.com/netbox-community/go-netbox@latest: module github.com/netbox-community/go-netbox@latest found (v0.0.0-20220627164555-1099c67af5a7), but does not contain package github.com/netbox-community/go-netbox

Trying to install a specific part almost works, but then complains that it's not part of a main package:

go install github.com/netbox-community/go-netbox/netbox/client@latest
go: finding module for package github.com/opentracing/opentracing-go
go: finding module for package github.com/go-openapi/jsonpointer
go: finding module for package github.com/opentracing/opentracing-go/log
go: finding module for package go.mongodb.org/mongo-driver/bson
go: finding module for package github.com/oklog/ulid
go: finding module for package github.com/go-openapi/analysis
go: finding module for package github.com/mailru/easyjson/jwriter
go: finding module for package github.com/asaskevich/govalidator
go: finding module for package gopkg.in/yaml.v2
go: finding module for package github.com/go-openapi/spec
go: finding module for package github.com/mitchellh/mapstructure
go: finding module for package go.mongodb.org/mongo-driver/bson/bsontype
go: finding module for package go.mongodb.org/mongo-driver/bson/primitive
go: finding module for package github.com/mailru/easyjson/jlexer
go: finding module for package github.com/opentracing/opentracing-go/ext
go: finding module for package github.com/go-openapi/loads
go: found github.com/opentracing/opentracing-go in github.com/opentracing/opentracing-go v1.2.0
go: found github.com/opentracing/opentracing-go/ext in github.com/opentracing/opentracing-go v1.2.0
go: found github.com/opentracing/opentracing-go/log in github.com/opentracing/opentracing-go v1.2.0
go: found github.com/asaskevich/govalidator in github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
go: found github.com/mitchellh/mapstructure in github.com/mitchellh/mapstructure v1.5.0
go: found github.com/oklog/ulid in github.com/oklog/ulid v1.3.1
go: found go.mongodb.org/mongo-driver/bson in go.mongodb.org/mongo-driver v1.11.0
go: found go.mongodb.org/mongo-driver/bson/bsontype in go.mongodb.org/mongo-driver v1.11.0
go: found go.mongodb.org/mongo-driver/bson/primitive in go.mongodb.org/mongo-driver v1.11.0
go: found github.com/mailru/easyjson/jlexer in github.com/mailru/easyjson v0.7.7
go: found github.com/mailru/easyjson/jwriter in github.com/mailru/easyjson v0.7.7
go: found gopkg.in/yaml.v2 in gopkg.in/yaml.v2 v2.4.0
go: found github.com/go-openapi/analysis in github.com/go-openapi/analysis v0.21.4
go: found github.com/go-openapi/loads in github.com/go-openapi/loads v0.21.2
go: found github.com/go-openapi/spec in github.com/go-openapi/spec v0.20.7
go: found github.com/go-openapi/jsonpointer in github.com/go-openapi/jsonpointer v0.19.5
package github.com/netbox-community/go-netbox/netbox/client is not a main package

It's not clear how to install and use this with Go 1.19.

stefanmcshane commented 1 year ago

go.mod file not found in current directory or any parent directory; see 'go help modules'

Try running the command from a directory that contains a go.mod

vwbusguy commented 1 year ago

Yeah, that's how I eventually got it to work, after longer than I want to admit it took me to get that far. While I can't expect the NetBox docs to explain the differences between go packaging in 1.19 vs previous versions, it would be nice to at least update the install instructions with the right command and mention the go.mod dependency as go get is now deprecated.

v0ctor commented 1 year ago

The readme has been update to clarify the way the library should be installed and used.