Office of Secret Intelligence

Who taught you to be a spy, fucking Gallagher!?!

Golang Application Namespacing

I'm no guru when it comes to golang intricacies, and this one actually put me off go a few times, but I've finally figured out how to have your library and instance application play together in the same directory for go apps.

 

Here's a little clarification:

 

This is the basic go app structure that you're told to use from day one (so sayeth https://golang.org/doc/code.html).  It is correct.

However, this doesn't really help address say, "what if I want my library that I wrote and my application using it to live in the same git repository?"

The problem I run into is some sort of namespace clashing, where go complains about "package main" and "package myapp" existing in the same place.

Long story short, my solution was to create an "app" directory underneath my library's root directory, like this:

This seems to do the trick for my purposes, allowing me to maintain my library and instance code in the same git repository while allowing everything to compile properly.


Sign in to reply

Replies: