On Friday, February 17, 2017 at 11:00:41 PM UTC+4, Diego Medina wrote: > > Hi, > > I think you pasted the same content to test.go as well as second.go > > in any case, if you use go run, you need to specify all the files involved: > > go run test.go second.go > > should do the trick > > That being said, unless you are writing small scripts using Go, I would > not recommend doing this, instead have a main.go with a package main, then > if you have some library code you can put them in the package second and > then > > go install > > and then > > run it as $GOPATH/bin/<binary-name-here> > > P.S. you can add $GOPATH/bin to your $PATH and then just call > > $<binary-name-here> > > Also, don't use relative imports like the one you posted from the "The Way > to Go", that is't really what you are supposed to do. Instead, you should > import it like > > import( > "github.com/user/test/second" > ) > > even when you are inside your test repository. > > And finally, you don't need to set GOROOT any more either, unless you have > a custom path to it, etc > > > Thanks > > > > > > On Friday, February 17, 2017 at 3:42:17 AM UTC-5, fsn7...@gmail.com wrote: >> >> In /etc/profile I have: >> >> export PATH=$PATH:/usr/local/go/bin >> export GOPATH=$HOME/work >> export GOROOT=/usr/local/go >> >> I have 2 source files: test.go (main) and second.go They located in >> >> /home/u001/work/src/github.com/user/test/ >> >> When I'm running go run test.go from test it gives me: >> >> test.go:5:2: open /home/u001/work/src/github.com/user/test/second: no such >> file or directory >> >> >> Content of test.go: >> >> package second >> >> import "fmt" >> >> var x int >> var y int >> >> func init() { >> x = 44 >> y = 100 >> } >> >> func ShowXY() { >> fmt.Printf("X:%d;Y%d.",x,y) >> } >> >> >> Content of second.go: >> >> package second >> >> import "fmt" >> >> var x int >> var y int >> >> func init() { >> x = 44 >> y = 100 >> } >> >> func ShowXY() { >> fmt.Printf("X:%d;Y%d.",x,y) >> } >> >> >> How to be if two source files are in one folder, let's say they both in >> ~/. It works when I had second.go in second/ and changed line to >> ../second. >> In the book "The Way to Go", listing 4.7 - it is said that in example >> below package is imported from the same directory. >> package main >> import ( >> “fmt” >> “./trans” >> ) >> var twoPi = 2 * trans.Pi >> func main() { >> fmt.Printf(“2*Pi = %g\n”, twoPi) // 2*Pi = 6.283185307179586 >> } >> >> >> Thanks. >> >
> Just in case - this is what I meant for second.go: >> > package main import "./second" func main(){ second.ShowXY(); } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.