Here is a tip for importing into your project. First, you import with the folder path but you use the declared package name in the imported class as the anchor to the methods in the imported class.
For example, let's say you have your project in the following structure:
example
main.go
pwd/
foldering.go
To import foldering.go even if the package name declared in foldering.go is different e.g. secondPwd into main.go
main.go
package main
import (
"example/pwd"
)
func main(){
secondPwd.PrintPWD();
}
foldering.go
package secondPwd
import(
"os"
"fmt"
"log"
)
//PrintPWD...
func PrintPWD() {
dir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
fmt.Println(dir)
}
Comments
Post a Comment