--- title: Source File Organization description: date: 2024-03-09 id: 20240309102252 taxonomies: categories: - development tags: - golang references: - Yoon, H. (2022). Go mini reference: A quick guide to the go programming language for busy coders. Independently Published. license: All rights reserved. --- Each source file of a Go package consists of three parts, in the following order. 1. A `package` clause defining the package to which it belongs. 2. A set of `import` declarations that declare imported packages, if any. 3. A (possibly empty) set of top-level declarations of constants, types, variables, functions, and methods. [TODO: Incluir apartado sobre «top-level declarations»]: # > :memo: All top-level declarations belong to a `package`, and not to a specific source file where they are declared. One of the primary purposes of using multiple files would be for organizing the code in a given `package`, e.g., for readability, for maintainability, etc. How the code in a `package` is divided into multiple source files is generally of no consequence to Go. One notable exception is the program initialization process. The language specification does not define the precise order. Different build systems may read the source files of a given package in different orders. The standard go toolchain reads the source files of a `package` in a lexical order using their file names. [TODO: Incluir apartado sobre «go toolchain» https://www.thegowiki.com/wiki/Go_Toolchain]: # The names introduced through `import` declarations, if any, may be referenced in the particular source file only, not across the package. This is referred to as the "source file scope". [TODO: Incluir apartado sobre «source file scope»]: #