# How Packages Work in Go

DevFeed: [How Packages Work in Go](<https://devfeed.tech/articles/how-packages-work-in-go-22057.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2013/07/how-packages-work-in-go-language.html>)

Published: 2013-07-05T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Filesystems](<https://devfeed.tech/topics/filesystems.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [files](<https://devfeed.tech/tags/files.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [programming](<https://devfeed.tech/tags/programming.md>), [project](<https://devfeed.tech/tags/project.md>), [structure](<https://devfeed.tech/tags/structure.md>)

## AI overview

A tutorial on organizing Go code with packages and the workspace directory convention. It explains creating a workspace with a required src directory, arranging application and package directories, and adding the workspace to GOPATH.

## Source excerpt

Since I started writing code in Go it has been a mystery to me how best to organize my code and use the package keyword. The package keyword is similar to using a namespace in C#, however the convention is to tie the package name to the directory structure. Go has this web page that attempts to explain how to write Go Code. External resource on golang.org: http://golang.org/doc/code.html When I started programming in Go this was one of the first documents I read. This went way over my head, mainly because I have been working in Visual Studio and code is packaged for you in Solution and Project files. Working out of a directory on the file system was a crazy thought. Now I love the simplicity of it but it has taken quite a while for it all to make sense. "How to Write Go Code" starts out with the concept of a Workspace. Think of this as the root directory for your project. If you were working in Visual Studio this is where the solution or project file would be located. Then from inside your Workspace you need to create a single sub-directory called src. This is mandatory if you want the Go tools to work properly. From within the src directory you have the freedom to organize your code the way you want. However you need to understand the conventions set forth by the Go team for packages and source code or you could be refactoring your code down the line. On my machine I created a Workspace called Test and the required sub-directory called src. This is the first step in creating your project. Screen Shot Screen Shot Then in LiteIDE open the Test directory (the Workspace), and create the following sub-directories and empty Go source code files. First we create a sub-directory for the application we are creating. The name of the directory where the main function is located will be the name of the executable. In our case main.go conta