Does it make sense to have two packages in the same directory?

Just move your packages inside a new folder within the same directory of main.go.
Remember to import the new package from the reference of the $GOPATH.


user@user:~/p/go/test/so-multipack$ ls -R
a  main.go

user@user:~/p/go/test/so-multipack$ cat main.go 
package main

import (
func main(){
user@user:~/p/go/test/so-multipack$ cat a/a.go 
package a
import (
func Hello(){
    fmt.Println("hello from a")
user@user:~/p/go/test/so-multipack$ go run main.go 
hello from a
user@user:~/p/go/test/so-multipack$ go build 
user@user:~/p/go/test/so-multipack$ ls
a  main.go  so-multipack

Useful link:

go build vs go build file.go

Leave a Comment