Sergei Basharov
Sergei Basharov

Reputation: 53920

How to import an existing library into Go 1.11 as a module?

I am trying out Go 1.11 beta2 with this modules support https://tip.golang.org/cmd/go/#hdr-Modules__module_versions__and_more.

I have created go.mod file looking like this:

module example.com/m

require github.com/aws/aws-sdk-go/aws v1.15.0
require github.com/aws/aws-sdk-go/aws/session v1.15.0
require github.com/aws/aws-sdk-go/service/s3 v1.15.0

But this shows me an error when trying to build:

go: github.com/aws/aws-sdk-go/[email protected]: unknown revision aws/v1.15.0 go: github.com/aws/aws-sdk-go/service/[email protected]: unknown revision service/s3/v1.15.0 go: github.com/aws/aws-sdk-go/aws/[email protected]: unknown revision aws/session/v1.15.0 go: error loading module requirements

So, I have a question, should I wait for the moment vendor adds support of modules versions into the library before I can import it using go modules or is there some other syntax I can use right now?

Upvotes: 2

Views: 2052

Answers (1)

Everton
Everton

Reputation: 13855

Your module's go.mod should require entire modules.

Try replacing:

require github.com/aws/aws-sdk-go/aws v1.15.0

With:

require github.com/aws/aws-sdk-go v1.15.0

You can see the AWS SDK module is defined as github.com/aws/aws-sdk-go here:

https://github.com/aws/aws-sdk-go/blob/master/go.mod

See also this example of a real repository depending on multiple modules from other repositories:

https://github.com/google/go-cloud/blob/master/go.mod

Upvotes: 1

Related Questions