{"id":47283,"date":"2015-03-02T19:34:54","date_gmt":"2015-03-02T16:34:54","guid":{"rendered":"https:\/\/www.altoros.com\/blog\/?p=47283"},"modified":"2019-11-27T18:06:17","modified_gmt":"2019-11-27T15:06:17","slug":"golang-internals-part-1-main-concepts-and-project-structure","status":"publish","type":"post","link":"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/","title":{"rendered":"Golang Internals, Part 1: Main Concepts and Project Structure"},"content":{"rendered":"<p><center><small><strong>Part 1<\/strong> | <a href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-2-diving-into-the-go-compiler\/\">Part 2<\/a> | <a href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-3-the-linker-object-files-and-relocations\/\">Part 3<\/a> | <a href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-4-object-files-and-function-metadata\/\">Part 4<\/a> | <a href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-5-the-runtime-bootstrap-process\/\">Part 5<\/a> | <a href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-6-bootstrapping-and-memory-allocator-initialization\/\">Part 6<\/a><\/small><\/center><\/p>\n<p>&nbsp;<br \/>\n<a href=\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2015\/03\/golang-icon.png\"><img decoding=\"async\" src=\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2015\/03\/golang-icon.png\" alt=\"\" width=\"150\" class=\"alignright size-full wp-image-47313\" \/><\/a><\/p>\n<p>This series of blog posts is intended for those who are already familiar with the basics of Go and would like to get a deeper insight into its internals. This tutorial is dedicated to the structure of the Go source code and some internal details of the Go compiler. After reading this, you should be able to answer the following questions:<\/p>\n<ol>\n<li>What is the structure of the Go source code?<\/li>\n<li>How does the Go compiler work?<\/li>\n<li>What is the basic structure of a node tree in Go?<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#Getting_started\" >Getting started<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#Understanding_a_project_structure\" >Understanding a project structure<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#Inside_the_Go_compiler\" >Inside the Go compiler<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#Diving_into_the_Go_grammar\" >Diving into the Go grammar<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#Understanding_nodes\" >Understanding nodes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#Further_reading\" >Further reading<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Getting_started\"><\/span>Getting started<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>When you start learning a new programming language, you can usually find a lot of \u201chello-world\u201d tutorials, beginner guides, and books with details on the main language concepts, syntax, and even the standard library. However, getting information on such things as the layout of major data structures that the language runtime allocates or what assembly code is generated when you call a built-in function is not that easy. Obviously, the answers lie inside the source code, but, from our own experience, you can spend hours wandering through it without making much progress. The goal of this article is to demonstrate how you can decipher Go sources on your own.<\/p>\n<p>Before we can begin, we certainly need our own copy of the Go source files. There is nothing special in getting them. Just execute the command below.<\/p>\n<pre style=\"padding-left: 20px;\">git clone <a href=\"https:\/\/github.com\/golang\/go\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/golang\/go<\/a><\/pre>\n<p>Please note that the code in the main branch is being constantly changed, so we use the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">release-branch.go1.4<\/code> branch in this blog post.<\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Understanding_a_project_structure\"><\/span>Understanding a project structure<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If you look at the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">\/src<\/code> folder of the Go repository, you can see a lot of folders. Most of them contain source files of the standard Go library. The standard naming conventions are always applied here, so each package is inside a folder with a name that directly corresponds to the package name. Apart from the standard library, there is a lot of other stuff. In our opinion, the most important and useful folders are listed in the table below.<\/p>\n<style type=\"text\/css\"><!--\n.myTable { background-color: transparent; border-collapse: collapse; } .myTable th { background-color: transparent; color: black; width:20%; } .myTable td, .myTable th { padding: 5px; border: 1px solid #989898; }\n--><\/style>\n<table class=\"myTable\">\n<tbody>\n<tr>\n<th><center>Folder<\/center><\/th>\n<th style=\"width: 530px;\" width=\"70%\"><center>Description<\/center><\/th>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/golang\/go\/tree\/release-branch.go1.4\/src\/cmd\" target=\"_blank\" rel=\"noopener noreferrer\">\/src\/cmd\/<\/a><\/td>\n<td>Contains different command line tools.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/golang\/go\/tree\/release-branch.go1.4\/src\/cmd\/go\" target=\"_blank\" rel=\"noopener noreferrer\">\/src\/cmd\/go\/<\/a><\/td>\n<td>Contains source files of a Go tool that downloads and builds Go source files and installs packages. While doing this, it collects all source files and makes calls to the Go linker and Go compiler command line tools.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/golang\/go\/tree\/release-branch.go1.4\/src\/cmd\/dist\" target=\"_blank\" rel=\"noopener noreferrer\">\/src\/cmd\/dist\/ <\/a><\/td>\n<td>Contains a tool responsible for building all other command line tools and all the packages from the standard library. You may want to analyze its source code to understand what libraries are used in every particular tool or package.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/golang\/go\/tree\/release-branch.go1.4\/src\/cmd\/gc\" target=\"_blank\" rel=\"noopener noreferrer\">\/src\/cmd\/gc\/<\/a><\/td>\n<td>This is the architecture-independent part of the Go compiler.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/golang\/go\/tree\/release-branch.go1.4\/src\/cmd\/ld\" target=\"_blank\" rel=\"noopener noreferrer\">\/src\/cmd\/ld\/<\/a><\/td>\n<td>The architecture-independent part of the Go linker. Architecture-dependent parts are located in the folder with the \u201cl\u201d postfix that uses the same naming conventions as the compiler.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/golang\/go\/tree\/release-branch.go1.4\/src\/cmd\/5a\" target=\"_blank\" rel=\"noopener noreferrer\">\/src\/cmd\/5a\/<\/a>, 6a, 8a, and 9a<\/td>\n<td>Here you can find Go assembler compilers for different architectures. The Go assembler is a form of assembly language that does not map precisely to the assembler of the underlying machine. Instead, there is a distinct compiler for each architecture that translates the Go assembler to the machine\u2019s assembler. You can find more details in the <a href=\"https:\/\/go.dev\/doc\/asm\" target=\"_blank\" rel=\"noopener noreferrer\">official documentation<\/a>.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/golang\/go\/tree\/release-branch.go1.4\/src\/lib9\" target=\"_blank\" rel=\"noopener noreferrer\">\/src\/lib9\/<\/a>, <a href=\"https:\/\/github.com\/golang\/go\/tree\/release-branch.go1.4\/src\/libbio\" target=\"_blank\" rel=\"noopener noreferrer\">\/src\/libbio<\/a>, <a href=\"https:\/\/github.com\/golang\/go\/tree\/release-branch.go1.4\/src\/liblink\" target=\"_blank\" rel=\"noopener noreferrer\">\/src\/liblink<\/a><\/td>\n<td>Different libraries that are used inside the compiler, linker, and runtime package.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/golang\/go\/tree\/release-branch.go1.4\/src\/runtime\" target=\"_blank\" rel=\"noopener noreferrer\">\/src\/runtime\/<\/a><\/td>\n<td>The most important Go package that is indirectly included into all programs. It contains the entire runtime functionality, such as memory management, garbage collection, goroutines creation, etc.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Inside_the_Go_compiler\"><\/span>Inside the Go compiler<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>As we mentioned above, the architecture-independent part of the Go compiler is located in the <a href=\"https:\/\/github.com\/golang\/go\/tree\/release-branch.go1.4\/src\/cmd\/gc\" target=\"_blank\" rel=\"noopener noreferrer\">\/src\/cmd\/gc\/<\/a> folder. The entry point is located in the <a href=\"https:\/\/github.com\/golang\/go\/blob\/release-branch.go1.4\/src\/cmd\/gc\/lex.c#L199\" target=\"_blank\" rel=\"noopener noreferrer\">lex.c<\/a> file. Apart from some common stuff, such as parsing command line arguments, the compiler does the following:<\/p>\n<ul>\n<li style=\"margin-bottom: 6px;\">Initializes some common data structures.<\/li>\n<li style=\"margin-bottom: 6px;\">Iterates through all of the provided Go files and calls the yyparse method for each file. This causes actual parsing to occur. The Go compiler uses <a href=\"http:\/\/www.gnu.org\/software\/bison\/\" target=\"_blank\" rel=\"noopener noreferrer\">Bison<\/a> as the parser generator. The grammar for the language is fully described in the <a href=\"https:\/\/github.com\/golang\/go\/blob\/release-branch.go1.4\/src\/cmd\/gc\/go.y\" target=\"_blank\" rel=\"noopener noreferrer\">go.y<\/a> file (I will provide more details on it later). As a result, this step generates a complete parse tree where each node represents an element of the compiled program.<\/li>\n<li style=\"margin-bottom: 6px;\">Recursively iterates through the generated tree several times and applies some modifications, e.g., defines type information for the nodes that should be implicitly typed, rewrites some language elements\u2014such as typecasting\u2014into calls to some functions in the runtime package and does some other work.<\/li>\n<li style=\"margin-bottom: 6px;\">Performs the actual compilation after the parse tree is complete. Nodes are translated into assembler code.<\/li>\n<li style=\"margin-bottom: 6px;\">Creates the object file that contains generated assembly code with some additional data structures, such as the symbols table, which is generated and written to the disk.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Diving_into_the_Go_grammar\"><\/span>Diving into the Go grammar<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Now, lets take a closer look at the second step. The <a href=\"https:\/\/github.com\/golang\/go\/blob\/release-branch.go1.4\/src\/cmd\/gc\/go.y\" target=\"_blank\" rel=\"noopener noreferrer\">go.y<\/a> file that contains the language grammar is a good starting point for investigating the Go compiler and the key to understanding the language syntax. The main part of this file consists of declarations, similar to the following:<\/p>\n<pre style=\"padding-left: 20px;\">xfndcl:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0LFUNC fndcl fnbody\r\n\r\nfndcl:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0sym '(' oarg_type_list_ocomma ')' fnres\r\n| '(' oarg_type_list_ocomma ')' sym '(' oarg_type_list_ocomma ')' fnres<\/pre>\n<p>In this declaration, the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">xfndcl<\/code> and <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">fundcl<\/code> nodes are defined. The <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">fundcl<\/code> node can be in one of the two forms. The first form corresponds to the following language construct:<\/p>\n<pre style=\"padding-left: 20px;\">somefunction(x int, y int) int<\/pre>\n<p>and the second one to this language construct:<\/p>\n<pre style=\"padding-left: 20px;\">(t *SomeType) somefunction(x int, y int) int.<\/pre>\n<p>The <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">xfndcl<\/code> node consists of the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">func<\/code> keyword that is stored in the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">LFUNC<\/code> constant, followed by the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">fndcl<\/code> and <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">fnbody<\/code>nodes.<\/p>\n<p>An important feature of Bison (or Yacc) grammar is that it allows for placing arbitrary C code next to each node definition. The code is executed every time a match for this node definition is found in the source code. Here, you can refer to the result node as <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">$$<\/code> and to the child nodes as <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">$1<\/code>, <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">$2<\/code>, etc.<\/p>\n<p>It is easier to understand this through an example. Note that the following code is a shortcut version of the actual code.<\/p>\n<pre style=\"padding-left: 20px;\">fndcl:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sym '(' oarg_type_list_ocomma ')' fnres\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0t = nod(OTFUNC, N, N);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0t-&gt;list = $3;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0t-&gt;rlist = $5;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$$ = nod(ODCLFUNC, N, N);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$$-&gt;nname = newname($1);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$$-&gt;nname-&gt;ntype = t;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0declare($$-&gt;nname, PFUNC);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n| '(' oarg_type_list_ocomma ')' sym '(' oarg_type_list_ocomma ')' fnres<\/pre>\n<p>First, a new node is created, which contains type information for the function declaration. The <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">$3<\/code> argument list  and the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">$5<\/code> result list are referenced from this node. Then, the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">$$<\/code> result node is created. It stores the function name and the type node. As you can see, there can be no direct correspondence between definitions in the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">go.y<\/code> file and the node structure.<\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Understanding_nodes\"><\/span>Understanding nodes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Now it is time to take a look at what a node actually is. First of all, a node is a struct (you can find a definition <a href=\"https:\/\/github.com\/golang\/go\/blob\/release-branch.go1.4\/src\/cmd\/gc\/go.h#L245\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>). This struct contains a large number of properties, since it needs to support different kinds of nodes and different nodes have different attributes. Below is a description of several fields that I think are important to understand.<\/p>\n<style type=\"text\/css\"><!--\n.myTable { background-color:transparent;border-collapse:collapse; } .myTable th { background-color:transparent;color:black;width:20%; } .myTable td, .myTable th { padding:5px;border:1px solid #989898; }\n--><\/style>\n<table class=\"myTable\">\n<tbody>\n<tr>\n<th><center>Node struct field<\/center><\/th>\n<th style=\"width: 530px;\" width=\"70%\"><center>Description<\/center><\/th>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/golang\/go\/blob\/release-branch.go1.4\/src\/cmd\/gc\/go.h#L259\" target=\"_blank\" rel=\"noopener noreferrer\">op<\/a><\/td>\n<td>Node operation. Each node has this field. It distinguishes different kinds of nodes from each other. In our previous example, those were <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">OTFUNC<\/code> (operation type function) and <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">ODCLFUNC<\/code> (operation declaration function).<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/golang\/go\/blob\/release-branch.go1.4\/src\/cmd\/gc\/go.h#L295\" target=\"_blank\" rel=\"noopener noreferrer\">type<\/a><\/td>\n<td>This is a reference to another struct with type information for nodes that have type information (there are no types for some nodes, e.g., control flow statements, such as <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">if<\/code>, <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">switch<\/code>, or <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">for<\/code>).<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/github.com\/golang\/go\/blob\/release-branch.go1.4\/src\/cmd\/gc\/go.h#L309\" target=\"_blank\" rel=\"noopener noreferrer\">val<\/a><\/td>\n<td>This field contains the actual values for nodes that represent literals.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Now that you understand the basic structure of the node tree, you can put your knowledge into practice. In the next post, we will investigate what exactly the Go compiler generates, using a simple Go application as an example.<\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Further_reading\"><\/span>Further reading<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li><a href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-2-diving-into-the-go-compiler\/\">Golang Internals, Part 2: Diving Into the Go Compiler<\/a><\/li>\n<li><a href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-3-the-linker-object-files-and-relocations\/\">Golang Internals, Part 3: The Linker, Object Files, and Relocations<\/a><\/li>\n<li><a href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-4-object-files-and-function-metadata\/\">Golang Internals, Part 4: Object Files and Function Metadata<\/a><\/li>\n<li><a href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-5-the-runtime-bootstrap-process\/\">Golang Internals, Part 5: the Runtime Bootstrap Process<\/a><\/li>\n<li><a href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-6-bootstrapping-and-memory-allocator-initialization\/\">Golang Internals, Part 6: Bootstrapping and Memory Allocator Initialization<\/a><\/li>\n<\/ul>\n<hr \/>\n<p><center><small>This post was written by <b>Siarhei Matsiukevich<\/b> and edited by <a href=\"https:\/\/www.altoros.com\/blog\/author\/sophie.turol\/\">Sophia Turol<\/a> and <a href=\"https:\/\/www.altoros.com\/blog\/author\/alex\/\">Alex Khizhniak<\/a>.<\/small><\/center><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6<\/p>\n<p>&nbsp;\n<\/p>\n<p>This series of blog posts is intended for those who are already familiar with the basics of Go and would like to get a deeper insight into its internals. This tutorial is dedicated to [&#8230;]<\/p>\n","protected":false},"author":94,"featured_media":47358,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":"","_links_to":"","_links_to_target":""},"categories":[214],"tags":[895],"class_list":["post-47283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-research-and-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Golang Internals, Part 1: Main Concepts and Project Structure | Altoros<\/title>\n<meta name=\"description\" content=\"This blog post explains the structure of a Go-based project, dives into the Go compiler, and overviews a Go node.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Golang Internals, Part 1: Main Concepts and Project Structure | Altoros\" \/>\n<meta property=\"og:description\" content=\"Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 &nbsp; This series of blog posts is intended for those who are already familiar with the basics of Go and would like to get a deeper insight into its internals. This tutorial is dedicated to [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/\" \/>\n<meta property=\"og:site_name\" content=\"Altoros\" \/>\n<meta property=\"article:published_time\" content=\"2015-03-02T16:34:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-11-27T15:06:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2015\/03\/golang-internals-part-1-main-concepts-and-project-structure.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Siarhei Matsiukevich\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Siarhei Matsiukevich\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/\",\"url\":\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/\",\"name\":\"Golang Internals, Part 1: Main Concepts and Project Structure | Altoros\",\"isPartOf\":{\"@id\":\"https:\/\/www.altoros.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2015\/03\/golang-internals-part-1-main-concepts-and-project-structure.png\",\"datePublished\":\"2015-03-02T16:34:54+00:00\",\"dateModified\":\"2019-11-27T15:06:17+00:00\",\"author\":{\"@id\":\"https:\/\/www.altoros.com\/blog\/#\/schema\/person\/5c29ff93db657e3cf6552d5e642003d9\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#primaryimage\",\"url\":\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2015\/03\/golang-internals-part-1-main-concepts-and-project-structure.png\",\"contentUrl\":\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2015\/03\/golang-internals-part-1-main-concepts-and-project-structure.png\",\"width\":1024,\"height\":768},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.altoros.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Golang Internals, Part 1: Main Concepts and Project Structure\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.altoros.com\/blog\/#website\",\"url\":\"https:\/\/www.altoros.com\/blog\/\",\"name\":\"Altoros\",\"description\":\"Insight\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.altoros.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.altoros.com\/blog\/#\/schema\/person\/5c29ff93db657e3cf6552d5e642003d9\",\"name\":\"Siarhei Matsiukevich\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.altoros.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2016\/06\/Sergey-Matyukevich-150x150.jpg\",\"contentUrl\":\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2016\/06\/Sergey-Matyukevich-150x150.jpg\",\"caption\":\"Siarhei Matsiukevich\"},\"description\":\"Siarhei Matsiukevich is a Cloud Engineer and Go Developer at Altoros. With 6+ years in software engineering, he is an expert in cloud automation and designing architectures for complex cloud-based systems. An active member of the Go community, Siarhei is a frequent contributor to open-source projects, such as Ubuntu and Juju Charms.\",\"url\":\"https:\/\/www.altoros.com\/blog\/author\/siarhei-matsiukevich\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Golang Internals, Part 1: Main Concepts and Project Structure | Altoros","description":"This blog post explains the structure of a Go-based project, dives into the Go compiler, and overviews a Go node.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/","og_locale":"en_US","og_type":"article","og_title":"Golang Internals, Part 1: Main Concepts and Project Structure | Altoros","og_description":"Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 &nbsp; This series of blog posts is intended for those who are already familiar with the basics of Go and would like to get a deeper insight into its internals. This tutorial is dedicated to [...]","og_url":"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/","og_site_name":"Altoros","article_published_time":"2015-03-02T16:34:54+00:00","article_modified_time":"2019-11-27T15:06:17+00:00","og_image":[{"width":1024,"height":768,"url":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2015\/03\/golang-internals-part-1-main-concepts-and-project-structure.png","type":"image\/png"}],"author":"Siarhei Matsiukevich","twitter_misc":{"Written by":"Siarhei Matsiukevich","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/","url":"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/","name":"Golang Internals, Part 1: Main Concepts and Project Structure | Altoros","isPartOf":{"@id":"https:\/\/www.altoros.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#primaryimage"},"image":{"@id":"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#primaryimage"},"thumbnailUrl":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2015\/03\/golang-internals-part-1-main-concepts-and-project-structure.png","datePublished":"2015-03-02T16:34:54+00:00","dateModified":"2019-11-27T15:06:17+00:00","author":{"@id":"https:\/\/www.altoros.com\/blog\/#\/schema\/person\/5c29ff93db657e3cf6552d5e642003d9"},"breadcrumb":{"@id":"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#primaryimage","url":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2015\/03\/golang-internals-part-1-main-concepts-and-project-structure.png","contentUrl":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2015\/03\/golang-internals-part-1-main-concepts-and-project-structure.png","width":1024,"height":768},{"@type":"BreadcrumbList","@id":"https:\/\/www.altoros.com\/blog\/golang-internals-part-1-main-concepts-and-project-structure\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.altoros.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Golang Internals, Part 1: Main Concepts and Project Structure"}]},{"@type":"WebSite","@id":"https:\/\/www.altoros.com\/blog\/#website","url":"https:\/\/www.altoros.com\/blog\/","name":"Altoros","description":"Insight","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.altoros.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.altoros.com\/blog\/#\/schema\/person\/5c29ff93db657e3cf6552d5e642003d9","name":"Siarhei Matsiukevich","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.altoros.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2016\/06\/Sergey-Matyukevich-150x150.jpg","contentUrl":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2016\/06\/Sergey-Matyukevich-150x150.jpg","caption":"Siarhei Matsiukevich"},"description":"Siarhei Matsiukevich is a Cloud Engineer and Go Developer at Altoros. With 6+ years in software engineering, he is an expert in cloud automation and designing architectures for complex cloud-based systems. An active member of the Go community, Siarhei is a frequent contributor to open-source projects, such as Ubuntu and Juju Charms.","url":"https:\/\/www.altoros.com\/blog\/author\/siarhei-matsiukevich\/"}]}},"_links":{"self":[{"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/posts\/47283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/users\/94"}],"replies":[{"embeddable":true,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/comments?post=47283"}],"version-history":[{"count":23,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/posts\/47283\/revisions"}],"predecessor-version":[{"id":47844,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/posts\/47283\/revisions\/47844"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/media\/47358"}],"wp:attachment":[{"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/media?parent=47283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/categories?post=47283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/tags?post=47283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}