0

I want to use a functions in my libGo.go. All topics that I watched for solve my problem is to push my folder on GitHub and in my go.moduse line require github.com/pseudo/project. Last Information I don't put my project on my GOPATH.

Architecture:

.
├── go.mod
├── libGo
│   └── libGo.go
└── main.go

libGo.go

package libGo

import "fmt";

func Hello() {
    fmt.Println("Hello");
}

func Calcule(x, y int) int {
    return (x + y);
}

main.go

package main;

import (
    "fmt"

    "example.com/libGo/libGo"
);

func main()  {
    fmt.Println("I'm main function");
    libGo.Hello()
}

go.mod

module example.com/libGo/libGo

go 1.15

error message:

package command-line-arguments
    imports example.com/libGo/libGo
    imports example.com/libGo/libGo: import cycle not allowed

I am a beginner at Golang, so if you can explain to me with an example and a description of why what I have done doesn't work I would be grateful.

Topics Read(first answer with 46 votes): Accessing local packages within a go module (go 1.11)

Rayder-_-
  • 199
  • 1
  • 2
  • 13

1 Answers1

0

Your module is called example.com/libGo and the package within this module is called libGo. Therfore the full package name would be example.com/libGo/libGo.

You would need to adjust the import or the module name. When you adjust the import to example.com/libGo/libGo, the module name must stay example.com/libGo. When you adjust the module name to example.com, the import name must stay example.com/libGo. Adding the package name to both ones puts you in the same situation as before.

svenwltr
  • 17,002
  • 12
  • 56
  • 68
  • Thank's for your answer, but I have other problem, I edit my ask for explain my new bug @svenwltr – Rayder-_- Aug 26 '20 at 14:33
  • I litre question. I don't know if I should create a topic for this, but what exactly is ```example.com```? is it a website? Finally if I understand your new answer correctly, I just need to change the path in my ```main.go``` file import. I'm sorry my question is maybe stupid for you – Rayder-_- Aug 26 '20 at 14:49
  • The module name is a globally unique identifier for this project/module. Also it is used by Golang to fetch the module, so it knows where to get to module from. In your case it would make sense to call it `github.com/pseudo/project`. – svenwltr Aug 26 '20 at 14:55