Security with Go
上QQ阅读APP看书,第一时间看更新

Creating your first package

Within the ~/src directory, any directory you create is a package. The name of your directory becomes the name of the package or application. We need to first make sure that the src directory exists. Tilde (~) is a shortcut for your home directory similar to the $HOME variable. Refer to the following code block:

mkdir ~/src

Let's create a new package named hello for our first application:

cd ~/src
mkdir hello

A package is simply a directory. You can have one or more source files inside a package. Any subdirectories are treated as separate packages. A package can be an application with a main() function (package main), or it can be a library that can only be imported to other packages. This package doesn't have any files yet, but we'll write the first file in a moment. Don't worry too much about package structure for now. You can read more about package paths at https://golang.org/doc/code.html#PackagePaths.