Reza Motaee
Reza Motaee

Reputation: 21

Read variable from another file in same package name and same directory in golang

file A

package main

import "fmt"

func main() {
    fmt.Println(My_str)
}

file B

package main

var My_str string
    My_str = "hi"

run program with this command

go run .

but this error appears:

undefined: My_str

Upvotes: 0

Views: 74

Answers (1)

Reza Motaee
Reza Motaee

Reputation: 21

I change declare variable to this :

var My_str = "hi"

but this is'n solved and say:

undefined: My_str

Upvotes: 1

Related Questions