Go Packages

From NovaOrdis Knowledge Base
Revision as of 00:13, 7 September 2023 by Ovidiu (talk | contribs) (→‎Overview)
Jump to navigation Jump to search

Internal

Overview

Go modularization is build upon the concept of package.

A Go package is a collection of variables, functions and type definitions, such as structs, and interfaces that are inter-related and provide coherent, unified functionality. The intention behind bundling together such features into package is to make the design and the maintenance of large programs practical. Packages are units that can be easier understood and changed, and that can also evolve independently of other packages.

Packages provide a namespace for their names, and also the mechanisms to encapsulate code, hide implementation details and only expose features, such as variables, types or functions that are meant to be publicly consumed.

Package are declared by writing multiple code files annotated with the same package name, and are consumed in other packages by importing them with the import keyword.

Packages as Namespaces

Packages as Encapsulation Mechanism

Declaring Packages

Consuming Packages