Skip to main content

Command Palette

Search for a command to run...

An Introduction to GO Packages

Updated
β€’0 min read

GO Packages are like an imaginary box which can contain lots of GO files. In this respect, a package is only a directory inside your GO workspace containing one or more GO source files, or other GO packages. All files should belong to the same package and this is declared as the very first statement in GO code using the syntax:

package <packagename>

A package in GO can either be an Executable Package or a Library Package.

Executable vs Library Packages

Executable Packages

These are programs that can be run from the command line. A program is executable if it starts with the package main statement. Every executable program should have a main() function which serves as the entry point of an executable program.

An example of an executable program is one i have written in this post.

Library Packages

These are reusable pieces of code that are used by other programs to perform certain tasks. They encourage us to build upon existing code. They are non-executable and can be imported into any GO program.

A Library Package does not have a main() function. Functions in a Library Package can have any name and should be capitalized for it to be accessible outside the package.

Great examples of Library Packages are the packages found in the GO standard library. There are also several third-party packages some of which can be found here.

Conclusion

The purpose of this article was to introduces GO Packages and also explain what Executable and Library Packages are. In the next article, I will be demonstrating how to create Library Packages and how to use them in a project. Thanks for reading.πŸ‘‹πŸΌ

Code Samples - https://github.com/Fakorede/Learning-Golang

Golang: My Journey to Mastery

Part 3 of 6

I recently started learningπŸ“– the GO programming language. In this series, I will be sharingπŸ‘¨πŸ½β€πŸ« most of the stuff I'm learning on this journey to mastery.πŸ€“ I'm also open to learning from readers.

Up next

Variables in GO

Introduction GO stores a variable inside a computer memory. A variable occupies some space on the memory depending on the variables type. Variables are only created after you run your program so they only become alive at the runtime not the compile-t...

More from this blog