redbrain
redbrain

Reputation: 162

Go project with 2 executables

Hi all I am fairly new to Golang, I am writing a toy client and server app just to learn the libraries.

But I have the project folder:

philipherron@Philips-iMac {~/workspace/gospace/src/github.com/redbrain/station} $ echo $GOPATH
/Users/philipherron/workspace/gospace

I wanted to have 2 binaries:

But when I build I get:

philipherron@Philips-iMac {~/workspace/gospace/src/github.com/redbrain/station} $ go build github.com/redbrain/station/
# github.com/redbrain/station
./server.go:5: main redeclared in this block
    previous declaration at ./client.go:5

I guess this is because it looks like I am making to mains in the same package.

So I tried creating a client and a server subdir and have the binaries in each of those, but I get:

philipherron@Philips-iMac {~/workspace/gospace/src/github.com/redbrain/station} $ go build github.com/redbrain/station/client
go install github.com/redbrain/station/client: build output "client" already exists and is a directory

I guess this is because I have the layout of:

$ tree
.
├── client
│   └── client.go
└── server
    └── server.go

2 directories, 4 files

Not sure how to get around this, it would just be nice to have the same client and server in the same directory but maybe this is against how I should be doing things in go?

Upvotes: 6

Views: 5647

Answers (2)

fabmilo
fabmilo

Reputation: 48330

just rename your .go files. The compiler is trying to write to 'client' but 'client' is already taken by the directory.

$ tree
.
├── client
│   └── main.go
└── server
    └── main.go

2 directories, 4 files

And/Or create a script that outputs them with a different name go build -o client client/main.go

Upvotes: 8

DeepakM
DeepakM

Reputation: 61

along with with separate packages as above, if you set the GOBIN=$GOPATH/bin then it will create client and server in the bin dir and it will not collide with dir names

Upvotes: 0

Related Questions