Go Language Modularization: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 27: Line 27:
==Declaring Packages==
==Declaring Packages==
===<span id='main'></span>The <tt>main</tt> Package===
===<span id='main'></span>The <tt>main</tt> Package===
The <code>main</code> package produces an executable as result of its compilation. The <code>main</code> package must have a function called <code>main()</code>.
The <code>main</code> package produces an executable as result of its compilation. The <code>main</code> package must have a function called <code>main()</code>, which is where the code execution starts.


==Importing Packages==
==Importing Packages==

Revision as of 00:29, 15 August 2023

External

Internal

Overview

A standard organization of the files that are part of a project makes easier to share code with other people who also use the same standard. Go workspaces encourage such a standard.

Overview

Workspaces

The standard workspace layout is:

. 
├─ src
├─ pkg
└─ bin

This layout is recommended, but not enforced.

A workspace may contain multiple projects.

Define the relationship between workspace and the GOPATH variable.

Project

Packages

A package is a group of related source files. A package can be imported by other packages. Always, there must be one package called main, which produces an executable as result of its compilation. Other packages do not produce executables as result of their compilation.

Declaring Packages

The main Package

The main package produces an executable as result of its compilation. The main package must have a function called main(), which is where the code execution starts.

Importing Packages

Dependencies

TODO

Deplete, merge into this document and delete: