Issue with go-git API

82 views
Skip to first unread message

PK

unread,
Oct 10, 2022, 1:35:38 AM10/10/22
to golang-nuts
I am trying to use this git api(https://github.com/go-git/go-git), but before that I tried to run the provided example (i.e. cloning the repo by golang). So I run the program 
https://github.com/go-git/go-git/blob/master/_examples/clone/main.go

So when I run this program I used to get this error:
sample.go:7:2: no required module provides package github.com/go-git/go-git/v5: go.mod file not found in current directory or any parent directory; see 'go help modules'

sample.go:8:2: no required module provides package github.com/go-git/go-git/v5/_examples: go.mod file not found in current directory or any parent directory; see 'go help modules'

Please help me, how I can execute this?

I am using the following:
Go version: go version go1.18.1 linux/amd64
Platform:  Ubuntu 22.04.1 LTS

peterGo

unread,
Oct 10, 2022, 8:04:28 AM10/10/22
to golang-nuts
Follow the instructions in the error messages: see `go help modules`.

Martin Schnabel

unread,
Oct 10, 2022, 10:06:48 AM10/10/22
to golan...@googlegroups.com
Hi PK,

most of the time examples are single file programs to be used with go
run. if you are inside the module root that covers all the dependencies
(or decend into the relevant example folder) you can use `go run
main.go` to run the example file.

I just tired it with the same repository and it works as expected and
described.

have fun!

On 10/10/22 07:35, PK wrote:
> I am trying to use this git api(*https://github.com/go-git/go-git*), but
> before that I tried to run the provided example (i.e. cloning the repo
> by golang). So I run the program
> *https://github.com/go-git/go-git/blob/master/_examples/clone/main.go*
>
> So when I run this program I used to get this error:
> sample.go:7:2: no required module provides package
> github.com/go-git/go-git/v5: go.mod file not found in current directory
> or any parent directory; see 'go help modules'
>
> sample.go:8:2: no required module provides package
> github.com/go-git/go-git/v5/_examples: go.mod file not found in current
> directory or any parent directory; see 'go help modules'
>
> *Please help me, how I can execute this?*
>
> I am using the following:
> Go version: go version go1.18.1 linux/amd64
> Platform:  Ubuntu 22.04.1 LTS
>
> --
> You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to golang-nuts...@googlegroups.com
> <mailto:golang-nuts...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/353c43c7-99bc-4e85-bf94-a5daff749640n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/353c43c7-99bc-4e85-bf94-a5daff749640n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Brian Candler

unread,
Oct 10, 2022, 10:11:47 AM10/10/22
to golang-nuts
Basically, every program now needs a "go.mod" file.  Even a "hello world" program should be made like this:

mkdir hello
cd hello
go mod init example.com/hello    # this creates "go.mod"
vi hello.go   # create your program here
go run .

Whilst it still does work to say "go run hello.go" for a simple hello-world-and-nothing-else, as soon as it depends on any third-party libraries, it will fail.  You *must* include a go.mod file.  Then when you import external libraries, "go mod tidy" will fetch them for you, including their dependencies, and update go.mod

Reply all
Reply to author
Forward
0 new messages