Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go Module #178

Closed
cimnine opened this issue Aug 23, 2018 · 32 comments
Closed

Go Module #178

cimnine opened this issue Aug 23, 2018 · 32 comments

Comments

@cimnine
Copy link

cimnine commented Aug 23, 2018

The documentation suggests that one should use resty as follows:

import "gopkg.in/resty.v1"

(https://github.com/go-resty/resty/blob/ec17de1c59a99e0743dac77aaab6435f364fdc42/README.md#usage)

But this brakes with Go modules, because go.mod declares the module as follows:

resty/go.mod

Line 1 in ec17de1

module github.com/go-resty/resty

This causes troubles when I try to compile code with go11.1rc2 and go modules enabled.

All is fine when I import resty like this:

import "github.com/go-resty/resty"

Now there are two options:

a) Adjust the documentation and suggest to import "github.com/go-resty/resty"
b) Adjust the go.mod to be module "gopkg.in/resty.v1

Option (a) is good for all new project that start with go modules right away, but it's backward incompatible.
Option (b) would be good for projects that used plain go get or dep until now and upgrade to go.mod, because they don't have to change all the import statements. There are no further drawbacks, except that this option needs a new release with an updated go.mod.

@jeevatkm jeevatkm self-assigned this Aug 23, 2018
@jeevatkm
Copy link
Member

@cimnine I would like to clarify if understood correctly.

You mean to say using gopkg.in/resty.v1 with Go modules breaks the build, correct?


By nature of resty package it will work seamlessly with github.com/go-resty/resty and gopkg.in/resty.v1 in plain go get (on go1.11 it has to have GO111MODULE=off). It keeps backward compatibility with plain go get. Could you please try and let me know?

But if we use gopkg.in/resty.v1 with Go modules it will break, as you have mentioned go.mod defines it as github.com/go-resty/resty. This is expected behavior.

FYI, resty package currently does not enforce package import like package resty // import "github.com/go-resty/resty". I'm planning to do that for v2.0.0 release in favor of Go modules.

I understand, documentation on Usage section needs update for Go modules instructions. I will do (or you can also send PR). Thank you for bringing it up.

@cimnine
Copy link
Author

cimnine commented Aug 23, 2018

You mean to say using gopkg.in/resty.v1 with Go modules breaks the build, correct?

Yes.

github.com/go-resty/resty

This will work with plain go get as well.

I understand, documentation on Usage section needs update for Go modules instructions.

Yes.

But: Everybody who updates their current project to Go modules will have to adjust all import statements in the project from gopkg.in/resty.v1 to github.com/go-resty/resty. This would not be necessary, if go.mod would declare the project as gopkg.in/resty.v1.


What you do in v2 is up to you. The Go community suggests for major version increments to adjust the import path anyway, so switching from gopkg.in/... to github.com/... would not be extra effort.

@jeevatkm
Copy link
Member

Everybody who updates their current project to Go modules will have to adjust all import statements in the project from gopkg.in/resty.v1 to github.com/go-resty/resty. This would not be necessary, if go.mod would declare the project as gopkg.in/resty.v1.

Okay, let's update the go.mod to gopkg.in/resty.v1 and documentation update 😄

@jeevatkm
Copy link
Member

@cimnine I have updated the go.mod, could you try it out?

@cimnine
Copy link
Author

cimnine commented Aug 24, 2018

It's hard to test, because you'd have to release a new release to gopkg.in with the new go.mod. It's afaik not possible to clone reference master through gopkg.in.

@jeevatkm
Copy link
Member

@cimnine Yes you're correct. Directly we cannot get master via gopkg.in. But we can workaround that.

I believe you have gopkg.in/resty.v1 on your GOPATH. So goto $GOPATH/src/gopkg.in/resty.v1 and do git fetch && git checkout master && git pull.

I'm at work, I will make a release by EOD when I get home. Thanks.

@cimnine
Copy link
Author

cimnine commented Aug 24, 2018

I believe this is not how Go modules works. $GOPATH/src/gopkg.in/resty.v1 does not even exist on my system yet.

@jeevatkm
Copy link
Member

Thanks. I will make a release by EOD.

@jeevatkm jeevatkm added this to the v1.9.0 Milestone milestone Aug 25, 2018
@jeevatkm
Copy link
Member

Making v1.9.0 release.

@cimnine
Copy link
Author

cimnine commented Aug 27, 2018

It works now as expected! Thank you!

@vvarp
Copy link

vvarp commented Aug 28, 2018

When running go mod tidy on a project that uses resty as dependency, I am getting:

go: github.com/go-resty/resty@v1.9.0: parsing go.mod: unexpected module path "gopkg.in/resty.v1"

Not sure how to interpret that?

@jeevatkm
Copy link
Member

@vvarp As part this #178 issue, go.mod is updated to gopkg.in/resty.v1 so that existing resty users could migrate to Go modules without updating their import path to github.com/go-resty/resty. Please see the thread conversation and use gopkg.in/resty.v1.

On upcoming v2.0.0 release I will default and enforce import path to Go modules v2 path. I'm planning to remove distribution via gopkg.in v2 onward.

@vvarp
Copy link

vvarp commented Aug 28, 2018

Sorry, I forgot to mention that my go.mod is using gopkg.in/resty.v1 v1.9.0, however I still get the above when running go mod tidy

@jeevatkm
Copy link
Member

@vvarp Is Go module build failing too? Also which import path are you using in your project (gopkg.in/resty.v1 or github.com/go-resty/resty)?

@cimnine Could you please share your inputs from your testing?

@cimnine
Copy link
Author

cimnine commented Aug 29, 2018

@vvarp How do you require go-resty in your Go code? Make sure that you import "gopkg.in/resty.v1".

@zuf
Copy link

zuf commented Aug 29, 2018

I also have this issue.

in go.mod:

require gopkg.in/resty.v1 v1.9.0

import in go code:

import "gopkg.in/resty.v1"

go version go1.11 linux/amd64
go mod tidy says

go: github.com/go-resty/resty@v1.9.0: parsing go.mod: unexpected module path "gopkg.in/resty.v1"
go: error loading module requirements

@jeevatkm
Copy link
Member

@zuf @vvarp I will investigate it and get back to you. If any changes required I will do it.

@cimnine Can you try go mod tidy on your end please?

@cimnine
Copy link
Author

cimnine commented Aug 29, 2018

$ go mod tidy

$ 

It's all good.

@cimnine
Copy link
Author

cimnine commented Aug 29, 2018

I don't think that's the cause, but the example test uses the wrong import path:

https://github.com/go-resty/resty/blob/master/example_test.go#L19

Maybe if someone copied it and used it as template, then it would complain in go mod tidy.

@jeevatkm
Copy link
Member

@cimnine Thanks for your inputs. we both kind of doubted the same.

@vvarp @zuf I'm able to replicate the issue you have mentioned with v1.9.0.

What I did?

  • I have cleaned github.com/go-resty/resty and gopkg.in/resty.v1 from my GOPTAH. To make sure I don't have copies of resty.
  • Created a simple main.go with resty get request and go.mod with require gopkg.in/resty.v1 v1.9.0
  • All go mod commands success except go mod tidy and go mod why
  • After the go build; I have verified the path $GOPATH/pkg/mod/; it had both version of resty (gopkg.in and github.com).
  • Then I did grep of github.com/go-resty/resty on source code found example_test.go using github.com import path. (This moment I got a notification from github of @cimnine comment)
  • I have modified the $GOPATH/pkg/mod/gopkg.in/resty.v1@v1.9.0/example_test.go with gopkg.in import path
  • Now all go mod commands success and only gopkg.in version is exists in $GOPATH/pkg/mod/

I did not expected *_test.go files would cause an issue with go mod. Typically test deps should be separate.

Long story short, I have to update example_test.go with gopkg.in import path and make a release of v1.9.1

I will make an release when I get back to home.

@1e0ng
Copy link

1e0ng commented Sep 30, 2018

According to golang/go#24301 (Why must v0, v1 never appear),
it's not allowed to use

import "gopkg.in/resty.v1"

We should always write as

import "gopkg.in/resty"

@jeevatkm
Copy link
Member

@leonsim both of us understanding about go mod spec correct. And you're point is valid about not to use v1 in the import path and I agree with you.

However as you might have read this thread. I'm not planning introduce breaking change in minor version (I did before and reverted in v1.9.1) of changing import path. I'm plan to have breaking change in major version and moving away from gopkg.in in-favor of go mod.

go mod implementation has support for gopkg.in import path(s), it should work flawlessly with .vX in the import path (even though its away from spec).

Let's aim for resty v2. Thank you.

@1e0ng
Copy link

1e0ng commented Sep 30, 2018

Thank you, @jeevatkm

After I update go.mod to require gopkg.in/resty.v1 v1.9.1 and then go mod tidy works without any error.

@lanshipeng
Copy link

i have a similar problem,when i use go mod tidy or go build . it's not succeed.
image

@jeevatkm
Copy link
Member

jeevatkm commented Dec 4, 2018

@lanshipeng Could you please update the import path to gopkg.in/resty.v1 and add entry in the go.mod as require gopkg.in/resty.v1 v1.10.2

Then you should be good.

@lanshipeng
Copy link

@jeevatkm but i don't know where to update the import path ,i can't find where
transfer the "gopkg.in/resty.v1 "

@jeevatkm
Copy link
Member

jeevatkm commented Dec 4, 2018

@lanshipeng In your Go project search for github.com/go-resty/resty and replace it with gopkg.in/resty.v1

And if you have a file go.mod then open that file search for github.com/go-resty/resty and replace that line with gopkg.in/resty.v1 v1.10.2

@lanshipeng
Copy link

@jeevatkm ,thank you. after i replace "github.com/go-resty/resty" with "gopkg.in/resty.v1 v1.10.2" ,it's run ok

@jeevatkm
Copy link
Member

jeevatkm commented Dec 4, 2018

@lanshipeng You're welcome.

@tsouza
Copy link

tsouza commented May 24, 2019

I can't seem to get this working. I have cleared everything related to go-resty under GOPATH also fixed the import to be gopkg.in/resty.v1 and I got the following in go.mod: gopkg.in/resty.v1 v1.12.0. When I run go mod tidy I get:

go: github.com/go-resty/resty@v1.12.0: parsing go.mod: unexpected module path "gopkg.in/resty.v1"

@jeevatkm
Copy link
Member

@tsouza Please have a look this one #230 (comment) and try it out?

@tsouza
Copy link

tsouza commented May 27, 2019

@jeevatkm I have that fixed but still with the same issue. For now, I've dropped go-resty and I am using golang http.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

7 participants