I checked out this answer and for some reason either I was unable to comprehend properly or it didn't work
Also, Before I start, I got that How we can do it with github but I want to try it without github
To start let's say I have a main.go file
package main
import (
"fmt"
"math"
"subpack"
)
//You Import packages without using comma in Go, rather space or new line
//In VS Code, if you use aren't using the package and run then it will automatically removie it
func main() {
fmt.Println("hello world")
//We use math.Floor to round the nunmber
fmt.Println(math.Floor(2.7))
fmt.Println(math.Sqrt(16))
fmt.Println(subpack.Reverse)
}
Notice subpack
here, it is the custom package I made. The subpack exsist like this
And contains the following code
package subpack
//If we make this in the same root level of our main it will throw an error
func Reverse(s string) string {
runes := []rune(s)
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
runes[i], runes[j] = runes[j], runes[i]
}
return string(runes)
}
running our go is throwing following error
cannot find package "subpack" in any of:
/usr/local/go/src/subpack (from $GOROOT)
/Users/anilbhatia/go/src/subpack (from $GOPATH)
Question: Is it possible and if yes, How to use custom package without github and without making it in the GO main folder rather by simply referencing the folder containing our go
file from the directory we are working.