How to find your own package by using the moudle function of go1.11

I initialized go.mod in the Gopath/src directory and wrote a package myself, but always compiled an error, but there was no problem using the package on github


:

Code:
go.mod:

package config

import (
    "fmt"
)

func Config() {
    fmt.Println("mmmmmmmmmmm")
}

compilation keeps telling me that I can"t find the config package, but I can"t do it without moudle

Jan.19,2022

  1. module main this is definitely an inappropriate way to write
  2. The reason for the error in
  3. is that you define module main , but when you import config, a subpackage under the main package, the path is wrong main/config
  4. .

I have this problem, too, if config is only a subpackage of the current project, and if it is a package of the same level as main in the src directory.
the solution is to upload the config package to github and import it.
if config is a private package, you can only import it according to the private git path, but this method seems to have a problem with go get.

Menu