Lan: Golang OS: Win11 go version go1.19.4 windows/amd64
go env:
- set GO111MODULE=on
- GOPATH=e:\Develop\Go\
- GOROOT=E:\Develop\Go
I am trying to understand how to add my own package into main entry go file.
the structure of my files are the following:
e:\Develop\Go\src\stepik\main.go e:\Develop\Go\src\stepik\pkg\st.go
where stepik is a project
main.go is the following:
`package main
import "fmt"
import "pkg/st"
func main() {
a : 100
a++
st.stepik
fmt.Print(a)
}`
and st.go is the following:
`package st
import (
"fmt"
)
func LetsGo(a int) {
a++
fmt.Print(a)
}`
Also I add my project stepik into mod file by using the following commands:
E:\develop\go\src\stepik> go mod init
go: creating new go.mod: module stepik
go: to add module requirements and sums:
go mod tidy
PS E:\develop\go\src\stepik> go mod tidy
So file go.mod was created, and it contains the following:
`module stepik
go 1.19`
But when I try to execute my main.go file I am getting the following error: ** Build Error: go build -o e:\Develop\Go\src\Stepik__debug_bin.exe -gcflags all=-N -l . main.go:4:9: package pkg/st is not in GOROOT (E:\Develop\Go\src\pkg\st) (exit status 1) **
Please advice how to fix issue above? Thank you in advance.