Error Importing Golang Package

Asked

Viewed 60 times

-1

I’m trying to call a function from another package on main but when I import and try to use the exported function returns the error of "package functions imported but not used".

Function.go

(go/src/github.com/dashadelas/test/functions/Function.go)

package functions

import (
    "fmt"
)

func GetFunction() {
     fmt.Println("teste")
}

main go.

(go/src/github.com/dashadelas/teste/main.go)

package main

import (
    "github.com/dashadelas/teste/functions"
)

func main() {
    GetFunction()
}

Can anyone tell me the origin of this mistake? I executed the go mod init, go mod tydi and the go mod vendor also!

1 answer

0

You imported the package, but did not put its name before the function GetFunction, to fix, type the package name before using the function, example:

functions.GetFunction()

In addition, it may be necessary to go get, configure the GOPATH etc..


I created exactly the example on github to illustrate in practice: https://github.com/Dadinel/so497165

  • I think $GOPATH is quiet, because when I run "CD $GOPATH" it opens the Go folder!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.