Unexpected module path "github.com/sirupsen/logrus" - go

I've used "github.com/sirupsen/logrus" and I can't manage to remove it
I've tried
go mod tidy
go clean -modcache
This is the log:
go: github.com/Sirupsen/logrus#v1.4.0: parsing go.mod: unexpected module path "github.com/sirupsen/logrus"
I've even deleted the mod directory.

I've found the solution:
I've replace in go.mod
replace (
github.com/Sirupsen/logrus v1.3.0 => github.com/Sirupsen/logrus v1.0.6
github.com/Sirupsen/logrus v1.4.0 => github.com/sirupsen/logrus v1.0.6
github.com/Sirupsen/logrus v1.0.5 => github.com/sirupsen/logrus v1.0.5
)
github.com/Sirupsen/logrus/github.com/sirupsen/logrus is a breaking change; because an import path of github.com/Sirupsen/logrus now no longer works when in module mode (the irony). Hence I think the module release of github.com/Sirupsen/logrus/github.com/sirupsen/logrus should in fact have been a v2 release.
https://github.com/golang/go/issues/28489
https://github.com/golang/go/issues/26208

Related

Installing a Go tool from github and facing installation errors

I want to install this tool from github : https://github.com/ethicalhackingplayground/ssrf-tool
I am using the cmd : go install github.com/ethicalhackingplayground/ssrf-tool#latest
Output :
go: finding module for package github.com/projectdiscovery/gologger
go: finding module for package github.com/briandowns/spinner
go: finding module for package github.com/logrusorgru/aurora
go: found github.com/briandowns/spinner in github.com/briandowns/spinner v1.18.1
go: found github.com/logrusorgru/aurora in github.com/logrusorgru/aurora v2.0.3+incompatible
go: found github.com/projectdiscovery/gologger in github.com/projectdiscovery/gologger v1.1.4
# github.com/ethicalhackingplayground/ssrf-tool
..\..\..\go\pkg\mod\github.com\ethicalhackingplayground\ssrf-tool#v0.0.0-20200901082948-7f3cffc3c7bb\ssrftool.go:34:2: undefined: gologger.Printf
..\..\..\go\pkg\mod\github.com\ethicalhackingplayground\ssrf-tool#v0.0.0-20200901082948-7f3cffc3c7bb\ssrftool.go:35:2: undefined: gologger.Infof
..\..\..\go\pkg\mod\github.com\ethicalhackingplayground\ssrf-tool#v0.0.0-20200901082948-7f3cffc3c7bb\ssrftool.go:36:2: undefined: gologger.Infof
I am super new to golang, go installation is fine in my system because other tools from github are working fine.
If some changes are required in the code of this tool, please suggest so.
This sources created without go module support and an old version of gologger, here is a workaround:
Clone repository git clone git#github.com:ethicalhackingplayground/ssrf-tool.git
cd ssrf-tool create go.mod file with content:
module github.com/ethicalhackingplayground/ssrf-tool
go 1.17
require (
github.com/briandowns/spinner v1.18.1
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/projectdiscovery/gologger v1.0.1
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 // indirect
)
download deps go mod download
Build executable go build .
./ssrf-tool --help
Profit.
Here is the repo with the problem fixed.
go install github.com/R0X4R/ssrf-tool#latest
or
git clone https://github.com/R0X4R/ssrf-tool.git
cd ssrf-tool
go build ssrftool.go && mv ssrftool /usr/bin/

replace module failed goland

I'm having a hard time replacing a module within go.
I was trying to clean the cache, go get <PackageName>, explicitly telling the compiler to change the module path etc..
replace github.com/terraform-providers/terraform-provider-aws => github.com/hashicorp/terraform-provider-aws v1.2.3
I was digging online but non of the solutions I saw helped me.
GOROOT=C:\Program Files\Go #gosetup
GOPATH=C:\Users\omer\go #gosetup
"C:\Program Files\Go\bin\go.exe" mod tidy #gosetup
go: finding module for package github.com/hashicorp/terraform-provider-aws
go: finding module for package github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource
go: finding module for package github.com/hashicorp/terraform-plugin-sdk/v2/terraform
go: finding module for package github.com/hashicorp/terraform-plugin-sdk/v2/diag
go: finding module for package golang.org/x/crypto/ssh
go: finding module for package github.com/hashicorp/go-multierror
go: finding module for package github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema
go: finding module for package github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation
go: found github.com/hashicorp/go-multierror in github.com/hashicorp/go-multierror v1.1.1
go: found github.com/hashicorp/terraform-plugin-sdk/v2/diag in github.com/hashicorp/terraform-plugin-sdk/v2 v2.8.0
go: found github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema in github.com/hashicorp/terraform-plugin-sdk/v2 v2.8.0
go: found github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation in github.com/hashicorp/terraform-plugin-sdk/v2 v2.8.0
go: found github.com/ravendb/ravendb-go-client in github.com/ravendb/ravendb-go-client v0.0.0-00010101000000-000000000000
go: found github.com/ravendb/ravendb-go-client/serverwide/operations in github.com/ravendb/ravendb-go-client v0.0.0-00010101000000-000000000000
go: found github.com/ravendb/terraform-provider-ravendb/utils in github.com/ravendb/terraform-provider-ravendb v0.0.0-00010101000000-000000000000
go: found golang.org/x/crypto/ssh in golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
go: found github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource in github.com/hashicorp/terraform-plugin-sdk/v2 v2.8.0
go: found github.com/hashicorp/terraform-plugin-sdk/v2/terraform in github.com/hashicorp/terraform-plugin-sdk/v2 v2.8.0
go: found github.com/hashicorp/terraform-provider-aws in github.com/hashicorp/terraform-provider-aws v1.60.0
go: terraform-provider-ravendb/ravendb tested by
terraform-provider-ravendb/ravendb.test imports
github.com/hashicorp/terraform-provider-aws: github.com/hashicorp/terraform-provider-aws#v1.60.0: parsing go.mod:
module declares its path as: github.com/terraform-providers/terraform-provider-aws
but was required as: github.com/hashicorp/terraform-provider-aws

How to Import KFServing Client Package in Golang

We are using KFServing in our kubernetes cluster. The project provides InferenceService struct and clientset in the folder pkg/.
How to import these packages under pkg/client? My code is as below:
package main
import (
"fmt"
kfs
"github.com/kubeflow/kfserving/pkg/client/clientset/versioned"
)
func main() {
var clientset *kfs.Cientset
clientset = kfs.NewForConfig(nil)
fmt.Println(clientset)
}
Try go mod tidy i got (I need dev on specified version v0.5.1):
main imports
github.com/kubeflow/kfserving/pkg/client/clientset/versioned
imports
k8s.io/client-go/discovery imports
github.com/googleapis/gnostic/OpenAPIv2:
module github.com/googleapis/gnostic#latest found (v0.5.5),
but does not contain package
github.com/googleapis/gnostic/OpenAPIv2
main imports
github.com/kubeflow/kfserving/pkg/client/clientset/versioned
imports
...
Try compiling these code i got:
a lot of errors .....
After go get github.com/kubeflow/kfserving I got:
Then I changed the go.mod and reconfiged the kfseving version from v0.6.0 to v0.5.1 and then recompile these code, still got below error:
go build .
go: github.com/kubeflow/kfserving#v0.5.1: missing go.sum entry; to add it:
go mod download github.com/kubeflow/kfserving
contens of go.mod:
module main
go 1.16
require github.com/kubeflow/kfserving v0.5.1 // indirect
UPDATE
for kfserving v0.4.0 everything works well
Looking at the kfserving go.mod file at v0.5.1, I see a big block of replace directives. By design, replace directives “only apply in the main module's go.mod file and are ignored in other modules”, so it looks like kfserving has some technical debt here that they're passing on to you.
I started with an empty go.mod file and pasted in those replace directives. Then:
$ go get -d github.com/kubeflow/kfserving/pkg/client/clientset/versioned#v0.5.1
go get: added github.com/PuerkitoBio/purell v1.1.1
…
go get: added sigs.k8s.io/yaml v1.2.0
The .go source file needed a few fixes for typos and mismatched types. I fudged it to:
package main
import (
"fmt"
kfs "github.com/kubeflow/kfserving/pkg/client/clientset/versioned"
)
func main() {
var clientset *kfs.Clientset
clientset = kfs.NewForConfigOrDie(nil)
fmt.Println(clientset)
}
and then go build . succeeds:
$ go build -o /dev/null .
Now I'll run go mod tidy to clean up the go.mod and go.sum files:
$ go mod tidy
go: downloading github.com/stretchr/testify v1.5.1
…
go: downloading github.com/jmespath/go-jmespath v0.3.0
But wait! I've still got all of the technical debt from kfserving/go.mod — without any comments explaining the choice of versions! — and I'm passing that technical debt on to any downstream users. Let's see if I can improve the situation while I'm here.
Go 1.16 handles the exclude directive a lot better than previous Go versions did, so maybe I can use a couple of targeted exclude directives instead of the (rather large) replace hammer.
I'll start by committing the fixes so far. (If nothing else, I want to be able to git diff the requirements to see what has changed.)
$ git add *.go go.mod go.sum
$ git commit -m 'fixed kfserving build'
[main fd93b1d] fixed kfserving build
3 files changed, 1643 insertions(+), 2 deletions(-)
create mode 100644 go.sum
I notice that all of the replace directives apply to k8s.io paths, so I'll list the current versions of those paths to see what needs to be fixed:
$ go list -m k8s.io/...
k8s.io/api v0.19.2 => k8s.io/api v0.19.2
k8s.io/apiextensions-apiserver v0.19.2 => k8s.io/apiextensions-apiserver v0.19.2
k8s.io/apimachinery v0.19.2 => k8s.io/apimachinery v0.19.2
k8s.io/apiserver v0.19.2 => k8s.io/apiserver v0.19.2
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible => k8s.io/client-go v0.19.2
k8s.io/cloud-provider v0.19.2 => k8s.io/cloud-provider v0.19.2
k8s.io/code-generator v0.19.2 => k8s.io/code-generator v0.19.2
k8s.io/component-base v0.19.2 => k8s.io/component-base v0.19.2
k8s.io/csi-translation-lib v0.19.2 => k8s.io/csi-translation-lib v0.19.2
k8s.io/gengo v0.0.0-20200428234225-8167cfdcfc14
k8s.io/klog v1.0.0 => k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.2.0
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6
k8s.io/legacy-cloud-providers v0.17.4 => k8s.io/legacy-cloud-providers v0.19.2
k8s.io/test-infra v0.0.0-20200803112140-d8aa4e063646 => k8s.io/test-infra v0.0.0-20200803112140-d8aa4e063646
k8s.io/utils v0.0.0-20200912215256-4140de9c8800 => k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89
Most of those look fine, but there are three mismatched versions:
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible => k8s.io/client-go v0.19.2
…
k8s.io/legacy-cloud-providers v0.17.4 => k8s.io/legacy-cloud-providers v0.19.2
…
k8s.io/utils v0.0.0-20200912215256-4140de9c8800 => k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89
legacy-cloud-providers just needs an upgrade, so that should be easy enough to fix with go get — but it's not relevant to this package anyway so I can just let it float to whatever version it ends up at. I'll cut down the replace directives to just the two remaining modules and see how far I get:
replace (
k8s.io/client-go => k8s.io/client-go v0.19.2
k8s.io/utils => k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89
)
Now:
$ go mod tidy
$ go build -o /dev/null .
Ok, so the build is still good — I've made incremental progress, so I'll lock that in:
$ git add go.mod go.sum
$ git commit -m 'go.mod: remove irrelevant replacements'
[main cdbc1db] go.mod: remove irrelevant replacements
3 files changed, 456 insertions(+), 43 deletions(-)
rewrite go.mod (85%)
create mode 100755 m
Now let's try notching out the bad client-go versions with exclude directives:
$ go mod edit -exclude=k8s.io/client-go#v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
$ go list -m k8s.io/client-go
k8s.io/client-go v9.0.0+incompatible => k8s.io/client-go v0.19.2
$ go mod edit -exclude=k8s.io/client-go#v9.0.0+incompatible
$ go list -m k8s.io/client-go
k8s.io/client-go v0.19.2 => k8s.io/client-go v0.19.2
Now I'm at the client-go version I needed, so I can drop that replace directive:
$ go mod edit -dropreplace=k8s.io/client-go
$ go mod tidy
$ go build -o /dev/null .
And again lock it in:
$ git add go.mod go.sum
$ git commit -m 'go.mod: use exclude instead of replace to notch out unwanted client-go versions'
[main de69965] go.mod: use exclude instead of replace to notch out unwanted client-go versions
2 files changed, 21 insertions(+), 3 deletions(-)
Now let's see what's going on with this k8s.io/utils replacement. I suspect that it isn't really needed — the version will be upgraded a bit, but I'm betting it won't break the build. And, indeed, it seems to be fine:
$ go list -m k8s.io/utils
k8s.io/utils v0.0.0-20200912215256-4140de9c8800 => k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89
$ go mod edit -dropreplace=k8s.io/utils
$ go mod tidy
$ go build -o /dev/null .
$ go list -m k8s.io/utils
k8s.io/utils v0.0.0-20200912215256-4140de9c8800
So now I've successfully reduced that big nest of replace directives from kfserving to just a couple of exclude directives targeted retracted versions of k8s.io/client-go. Here's my whole go.mod file at the end of this process:
module example.com/m
go 1.16
exclude (
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
k8s.io/client-go v9.0.0+incompatible
)
require github.com/kubeflow/kfserving v0.5.1
This seems like a module cache issue cause that package appears to be there for v0.5.1. Do the following:
Clean the modcache go clean --modcache
Get the module the nice way via go get github.com/kubeflow/kfserving#v0.5.1
Run go mod tidy
Update
With the extra output I can see you you have an import error from a dependent module.
github.com/kubeflow/kfserving/pkg/client/clientset/versioned
imports
k8s.io/client-go/discovery imports
github.com/googleapis/gnostic/OpenAPIv2:
So version v0.5.1 imports k8s.io/client-go/discovery which imports github.com/googleapis/gnostic/OpenAPIv2 which no longer exists in the current release (but it is there is older releases). So it looks like you would need to fix the import version in client-go to avoid this issue.

go mod update dependencies and leave local

I have a package that uses some local packages
module mycompany.com/clientname/server
go 1.14
require (
github.com/lib/pq v1.7.0
github.com/99designs/gqlgen v0.11.3
github.com/vektah/gqlparser/v2 v2.0.1
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
mycompany.com/clientname/models v0.0.0-00010101000000-000000000000
mycompany.com/common/utils v0.0.0-00010101000000-000000000000
)
replace mycompany.com/common/utils => ../../common/utils
replace mycompany.com/clientname/models => ../models
the mycompany.com domain doesn't serve the package, it is just a fictional path (and I use it in my gopath ~/go/src/mycompany.com/...)
the problem is that when I run go get -u all, I want the 'valid' packages to be updated (like the github.com/lib/pq or github.com/99designs/gqlgen), but to leave the local (fictional) packages as they are.
but go get -u all just prints out the new versions, then prints the errors on the local packages and then doesn't change go.mod.
go: google.golang.org/grpc upgrade => v1.30.0
go: go.opencensus.io upgrade => v0.22.4
go: github.com/mattn/go-runewidth upgrade => v0.0.9
go: github.com/gogs/chardet upgrade => v0.0.0-20191104214054-4b6791f73a28
go: golang.org/x/text upgrade => v0.3.3
go: github.com/mitchellh/mapstructure upgrade => v1.3.2
go get all: unrecognized import path "mycompany.com/clientname/models": reading https://mycompany.com/clientname/models?go-get=1: 404 Not Found
go get all: unrecognized import path "mycompany.com/common/utils": reading https://mycompany.com/common/utils?go-get=1: 404 Not Found
The error from go get -u was a bug in the go command, fixed in the upcoming Go 1.16 release. See https://golang.org/issue/32567 for detail.
(That said, ideally you should be hosting the modules in version control and using GOPRIVATE=mycompany.com instead of slotting things in locally via replace directives.)

When i add go mod to my project, a can't run it, how can i fix it?

I wrote an app and when i add go modules to my project go mod init and try to start go run app.go i had an error: build command-line-arguments: cannot load github.com/nicksnyder/go-i18n/i18n: module github.com/nicksnyder/go-i18n#latest (v2.0.2+incompatible) found, but does not contain package github.com/nicksnyder/go-i18n/i18n. What can i do with this problem?
go.mod:
require (
github.com/BurntSushi/toml v0.3.1
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/dyatlov/go-opengraph v0.0.0-20180429202543-816b6608b3c8 // indirect
github.com/go-ldap/ldap v3.0.3+incompatible // indirect
github.com/gorilla/handlers v1.4.2
github.com/gorilla/mux v1.7.3
github.com/gorilla/websocket v1.4.1 // indirect
github.com/mattermost/mattermost-server v5.11.1+incompatible
github.com/pborman/uuid v1.2.0 // indirect
github.com/syndtr/goleveldb v1.0.0
go.uber.org/zap v1.12.0 // indirect
golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf // indirect
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
)
go.sum:
...
github.com/nicksnyder/go-i18n v2.0.2+incompatible
...
Check if you're importing the correct package. It looks like that package was moved to github.com/nicksnyder/go-i18n/i18n/v2, so import that instead.

Resources