-1

I have a version.go on my root folder(MyPackage).

package MyPackage
var (
    Version = "undifened"
    Hash = "undifined"
)

And I have second file found on MyPackage/cmd/bootloader/bootloader.go

package main
import(
       "MyPackage"
       "fmt"
)

func main() {
     fmt.Println(MyPackage.Version)
}

But I am gettingundeclared name: MyPackage and "MyPackage" imported but not used as ext on gotype and i dont know how to fix.

I tried executing this gotype bootloader.go and get this.

bootloader.go:9:14: undeclared name: MyPackage
bootloader.go:4:2: "MyPackage" imported but not used as ext

I will appreciate for any help will come.

Edit: This is not the same with Golang Global Variable access because this will defeat the purpose of that variables, because i don't want to rewrite it on the every main.go. because I want to build the main.go with the -ldflags to set the value on the variable.

Community
  • 1
  • 1
zer09
  • 1,507
  • 2
  • 28
  • 48
  • Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackoverflow.com/rooms/143035/discussion-on-question-by-zer09-how-to-call-a-variable-declared-on-the-root-pack). – Bhargav Rao Apr 30 '17 at 15:59

1 Answers1

2

If someone have this, doing go install on the directory where the main package is, makes the gotype stop spitting the message.

zer09
  • 1,507
  • 2
  • 28
  • 48