Hydra: Problem with import path for go-resty and go1.11 modules

Created on 29 Sep 2018  路  14Comments  路  Source: ory/hydra

In a toy project, I am trying to use the Hydra Go SDK.

I am using go1.11 with the new modules feature.

I am facing a problem when building because Go expect the lib github.com/go-resty/resty to be imported using the package gopkg.in/resty.v1 (see its go-mod's module instruction):

go: github.com/go-resty/[email protected]: parsing go.mod: unexpected module path "gopkg.in/resty.v1"
go: error loading module requirements

And the root cause of this, is this line here where you import github.com/go-resty/resty.

I see that this file seems NOT to be generated by swagger-codegen ?

Can I just send a PR to use the right import path for go-resty in api_client.go ?

Most helpful comment

Pin Hydra to a specific version:

go get github.com/ory/[email protected]+oryOS.10

All 14 comments

As a temporary workaround, I am running

sudo sed -i -e 's/"github.com\/go-resty\/resty"/resty "gopkg.in\/resty.v1"/g' \
    `$GOPATH/pkg/mod/github.com/ory/[email protected]/sdk/go/hydra/swagger/api_client.go`

The file is indeed generated by swagger but we have to revert it because the underlying code template does not support certain features we needed before. Open to change the import path as long as it doesn't break stuff.

@laibulle this is also exactly what I have done to workaround the problem. This is why I know the fix works.

@aeneasr If this file is indeed generated, maybe I should check with swagger-codegen then, we dont want to manually edit a file now and have the same problem appear later when we finally use the generated version.

We're manually updating it anyways because of a patch I had to add. So it's fine to hotfix this as a new commit. swagger-codegen is kinda f*ed anyways because they introduced a new version 2.4 (we're on 2.2 I think) which has a completely different template which is even worse than the one right now. version 3.0 is in rc I think but there are no templates yet, so even if you make a PR or issue it's unlikely that it will be fixed.

This is resolved

@pierredavidbelanger , need your help. error on loading resty package with go modules. when i use go mod tidy or go build . it's not succeed.
image

@lanshipeng I am sorry, I did not contributed to this project lately, you should try the chat and see with them if you should open a new issue for this.

But , as a workaround, try to not let _go_ choose the version for you (it will maybe not choose the right one), and target a specific version instead, one that we know this bug is fixed in.

for example, this is the last commit in the master branch:

go get github.com/ory/hydra@55654c084cc24a49d333e62773295cbf8bf5b31d

Still having the issue on brand new project. Bellow the steps:

mkdir go-sdk-test
cd go-sdk-test
go mod init testhydra

then in main.go:

package main

import (
    "fmt"

    "github.com/ory/hydra/sdk/go/hydra"
)

func main() {
    fmt.Println("Hi")
    _, _ := hydra.NewSDK(&hydra.Configuration{
        AdminURL: "https://hydra.localhost:4445",
    })

}

then

go mod tidy

go: finding github.com/ory/hydra/sdk/go/hydra latest
go: finding github.com/ory/hydra/sdk/go latest
go: finding github.com/ory/hydra/sdk latest
go: finding github.com/stretchr/testify/assert latest
go: finding golang.org/x/oauth2 latest
go: finding golang.org/x/oauth2/clientcredentials latest
go: github.com/go-resty/[email protected]: parsing go.mod: unexpected module path "gopkg.in/resty.v1"
go: error loading module requirements

go version go1.12 linux/amd64

Pin Hydra to a specific version:

go get github.com/ory/[email protected]+oryOS.10

@pierredavidbelanger
Thanks.
I pinned it in mo go.mod file:
require github.com/ory/hydra v1.0.0-rc.6+oryOS.10

It solver the problem, and it should work properly in the build scripts without go get ...

Not working after new release:

$ go get github.com/ory/[email protected]+oryOS.10
go: finding github.com/ory/hydra v1.0.0-rc.6
go get github.com/ory/[email protected]+oryOS.10: unknown revision v1.0.0-rc.6
$ go get github.com/ory/[email protected]+oryOS.10
go: finding github.com/ory/hydra v1.0.0-rc.8
go get github.com/ory/[email protected]+oryOS.10: unknown revision v1.0.0-rc.8

That's a diffrerent issue. You must use go get github.com/ory/[email protected] or go get github.com/ory/[email protected]

Hm, seems like go mod has issues with resolving tags like rc.8. I'll investigate. Also go-resty is freaking annoying and we'll move to go-swagger generated code instead.

This should be fixed now that we're no longer using swagger-codegen but go-swagger

Was this page helpful?
0 / 5 - 0 ratings

Related issues

audioXD picture audioXD  路  8Comments

flavioleggio picture flavioleggio  路  7Comments

safurabahrami picture safurabahrami  路  3Comments

aeneasr picture aeneasr  路  3Comments

atbentley picture atbentley  路  3Comments