Reputation: 61
Go structure:
|--main.go
|
|--users
|
|---users.go
The two files are very simple: main.go:
package main
import "./users"
func main() {
resp := users.GetUser("abcde")
fmt.Println(resp)
}
users.go:
package users
import "fmt"
func GetUser(userTok string) string {
fmt.Sprint("sf")
return "abcde"
}
But it seems fmt is not accessible in main.go. When I try to run the program, it gives
undefined: fmt in fmt.Println
Anybody knows how to make fmt accessible in main.go?
Upvotes: 5
Views: 2305
Reputation: 3940
You need to import fmt
in main
as well.
Simply write "fmt"
in import()
in main.go
and it should run.
import(
"fmt"
"./users"
)
Upvotes: 3