...

/

Custom Packages: Folder Structure, go install and go test

Custom Packages: Folder Structure, go install and go test

This lesson covers important concepts like folder structure of a custom package, testing the executable and installation under workspace.

For demonstration, we take a simple package uc which has a function UpperCase to turn a string into uppercase letters. This is just for demonstration purposes (it wraps the same functionality from package “strings”), but the same techniques can be applied to more complex packages.

Folder-structure for custom packages

The following structure is considered best practice and imposed by the go tool (where uc stands for a general package name; the names in bold are folders; italicized is the executable):

go_projects (a workspace in $GOPATH)
           src/uppercase

                        /uc (contains go code for package uc)
                            uc.go
                            uc_test.go
                        /uc_main
                            ucmain.go (main program for using package uc)
           
           pkg/windows_amd64 (the actual name depends on your operating system/architecture)

                        /uppercase
                        uc.a (object file of package)

bin                     (contains the final executable files)

                         uc_main.exe

Building the package uc in the uc folder

The functionality is implemented ...