[{"data":1,"prerenderedAt":1462},["ShallowReactive",2],{"navigation_docs":3,"-getting-started-first-program":377,"-getting-started-first-program-surround":1457},[4,39,114,144,184,244,293,362],{"title":5,"icon":6,"path":7,"stem":8,"children":9,"page":6},"Getting Started",false,"\u002Fgetting-started","1.getting-started",[10,15,20,25,30,35],{"title":11,"path":12,"stem":13,"icon":14},"Learning Path","\u002Fgetting-started\u002Flearning-path","1.getting-started\u002F1.learning-path","i-lucide-map",{"title":16,"path":17,"stem":18,"icon":19},"Introduction","\u002Fgetting-started\u002Fintroduction","1.getting-started\u002F2.introduction","i-lucide-house",{"title":21,"path":22,"stem":23,"icon":24},"Installation","\u002Fgetting-started\u002Finstallation","1.getting-started\u002F3.installation","i-lucide-download",{"title":26,"path":27,"stem":28,"icon":29},"Your First Program","\u002Fgetting-started\u002Ffirst-program","1.getting-started\u002F4.first-program","i-lucide-play",{"title":31,"path":32,"stem":33,"icon":34},"Modules and Dependencies","\u002Fgetting-started\u002Fmodules-and-dependencies","1.getting-started\u002F5.modules-and-dependencies","i-lucide-package-open",{"title":36,"path":37,"stem":38,"icon":34},"Advanced Modules","\u002Fgetting-started\u002Fadvanced-modules","1.getting-started\u002F6.advanced-modules",{"title":40,"path":41,"stem":42,"children":43,"page":6},"Fundamentals","\u002Ffundamentals","2.fundamentals",[44,49,54,59,64,69,74,79,84,89,94,99,104,109],{"title":45,"path":46,"stem":47,"icon":48},"Program Structure","\u002Ffundamentals\u002Fprogram-structure","2.fundamentals\u002F1.program-structure","i-lucide-workflow",{"title":50,"path":51,"stem":52,"icon":53},"Structs and Methods","\u002Ffundamentals\u002Fstructs-and-methods","2.fundamentals\u002F10.structs-and-methods","i-lucide-box",{"title":55,"path":56,"stem":57,"icon":58},"Interfaces","\u002Ffundamentals\u002Finterfaces","2.fundamentals\u002F11.interfaces","i-lucide-plug",{"title":60,"path":61,"stem":62,"icon":63},"Error Handling","\u002Ffundamentals\u002Ferrors","2.fundamentals\u002F12.errors","i-lucide-triangle-alert",{"title":65,"path":66,"stem":67,"icon":68},"Defined Types and Type Aliases","\u002Ffundamentals\u002Fdefined-types","2.fundamentals\u002F13.defined-types","i-lucide-tags",{"title":70,"path":71,"stem":72,"icon":73},"Generics","\u002Ffundamentals\u002Fgenerics","2.fundamentals\u002F14.generics","i-lucide-blocks",{"title":75,"path":76,"stem":77,"icon":78},"Project Structure","\u002Ffundamentals\u002Fproject-structure","2.fundamentals\u002F2.project-structure","i-lucide-folder-tree",{"title":80,"path":81,"stem":82,"icon":83},"Project Layout","\u002Ffundamentals\u002Fproject-layout","2.fundamentals\u002F3.project-layout","i-lucide-layout",{"title":85,"path":86,"stem":87,"icon":88},"Variables and Data Types","\u002Ffundamentals\u002Fvariables-and-types","2.fundamentals\u002F4.variables-and-types","i-lucide-variable",{"title":90,"path":91,"stem":92,"icon":93},"Functions","\u002Ffundamentals\u002Ffunctions","2.fundamentals\u002F5.functions","i-lucide-braces",{"title":95,"path":96,"stem":97,"icon":98},"Control Statements","\u002Ffundamentals\u002Fcontrol-statements","2.fundamentals\u002F6.control-statements","i-lucide-git-branch",{"title":100,"path":101,"stem":102,"icon":103},"Pointers","\u002Ffundamentals\u002Fpointers","2.fundamentals\u002F7.pointers","i-lucide-mouse-pointer-2",{"title":105,"path":106,"stem":107,"icon":108},"Arrays and Slices","\u002Ffundamentals\u002Farrays-and-slices","2.fundamentals\u002F8.arrays-and-slices","i-lucide-list",{"title":110,"path":111,"stem":112,"icon":113},"Maps","\u002Ffundamentals\u002Fmaps","2.fundamentals\u002F9.maps","i-lucide-table-properties",{"title":115,"path":116,"stem":117,"children":118,"page":6},"Concurrency","\u002Fconcurrency","3.concurrency",[119,124,129,134,139],{"title":120,"path":121,"stem":122,"icon":123},"Concurrency Model","\u002Fconcurrency\u002Fconcurrency-model","3.concurrency\u002F1.concurrency-model","i-lucide-network",{"title":125,"path":126,"stem":127,"icon":128},"Goroutines","\u002Fconcurrency\u002Fgoroutines","3.concurrency\u002F2.goroutines","i-lucide-git-fork",{"title":130,"path":131,"stem":132,"icon":133},"Channels","\u002Fconcurrency\u002Fchannels","3.concurrency\u002F3.channels","i-lucide-arrow-left-right",{"title":135,"path":136,"stem":137,"icon":138},"Select and Cancellation","\u002Fconcurrency\u002Fselect-and-cancellation","3.concurrency\u002F4.select-and-cancellation","i-lucide-circle-stop",{"title":140,"path":141,"stem":142,"icon":143},"Synchronization","\u002Fconcurrency\u002Fsynchronization","3.concurrency\u002F5.synchronization","i-lucide-lock-keyhole",{"title":145,"path":146,"stem":147,"children":148,"page":6},"Standard Library","\u002Fstandard-library","4.standard-library",[149,154,159,164,169,174,179],{"title":150,"path":151,"stem":152,"icon":153},"Standard Library Overview","\u002Fstandard-library\u002Foverview","4.standard-library\u002F1.overview","i-lucide-library",{"title":155,"path":156,"stem":157,"icon":158},"Text and Formatting","\u002Fstandard-library\u002Ftext-and-formatting","4.standard-library\u002F2.text-and-formatting","i-lucide-text",{"title":160,"path":161,"stem":162,"icon":163},"Files and JSON","\u002Fstandard-library\u002Ffiles-and-json","4.standard-library\u002F3.files-and-json","i-lucide-file-json",{"title":165,"path":166,"stem":167,"icon":168},"HTTP Clients and Servers","\u002Fstandard-library\u002Fhttp","4.standard-library\u002F4.http","i-lucide-server",{"title":170,"path":171,"stem":172,"icon":173},"Testing","\u002Fstandard-library\u002Ftesting","4.standard-library\u002F5.testing","i-lucide-flask-conical",{"title":175,"path":176,"stem":177,"icon":178},"Command-Line Tools and Configuration","\u002Fstandard-library\u002Fcommand-line-and-configuration","4.standard-library\u002F6.command-line-and-configuration","i-lucide-terminal-square",{"title":180,"path":181,"stem":182,"icon":183},"Structured Logging","\u002Fstandard-library\u002Fstructured-logging","4.standard-library\u002F7.structured-logging","i-lucide-scroll-text",{"title":185,"path":186,"stem":187,"children":188,"page":6},"Backend Development","\u002Fbackend-development","5.backend-development",[189,194,199,204,209,214,219,224,229,234,239],{"title":190,"path":191,"stem":192,"icon":193},"Backend Roadmap","\u002Fbackend-development\u002Fbackend-roadmap","5.backend-development\u002F1.backend-roadmap","i-lucide-route",{"title":195,"path":196,"stem":197,"icon":198},"Graceful Shutdown","\u002Fbackend-development\u002Fgraceful-shutdown","5.backend-development\u002F10.graceful-shutdown","i-lucide-power",{"title":200,"path":201,"stem":202,"icon":203},"Production Checklist","\u002Fbackend-development\u002Fproduction-checklist","5.backend-development\u002F11.production-checklist","i-lucide-clipboard-check",{"title":205,"path":206,"stem":207,"icon":208},"HTTP API Design","\u002Fbackend-development\u002Fhttp-api-design","5.backend-development\u002F2.http-api-design","i-lucide-waypoints",{"title":210,"path":211,"stem":212,"icon":213},"Middleware","\u002Fbackend-development\u002Fmiddleware","5.backend-development\u002F3.middleware","i-lucide-layers-3",{"title":215,"path":216,"stem":217,"icon":218},"Validation","\u002Fbackend-development\u002Fvalidation","5.backend-development\u002F4.validation","i-lucide-list-checks",{"title":220,"path":221,"stem":222,"icon":223},"Application Wiring","\u002Fbackend-development\u002Fapplication-wiring","5.backend-development\u002F5.application-wiring","i-lucide-cable",{"title":225,"path":226,"stem":227,"icon":228},"Observability","\u002Fbackend-development\u002Fobservability","5.backend-development\u002F6.observability","i-lucide-activity",{"title":230,"path":231,"stem":232,"icon":233},"Database SQL","\u002Fbackend-development\u002Fdatabase-sql","5.backend-development\u002F7.database-sql","i-lucide-database",{"title":235,"path":236,"stem":237,"icon":238},"Transactions","\u002Fbackend-development\u002Ftransactions","5.backend-development\u002F8.transactions","i-lucide-repeat-2",{"title":240,"path":241,"stem":242,"icon":243},"Authentication and Authorization","\u002Fbackend-development\u002Fauthentication","5.backend-development\u002F9.authentication","i-lucide-shield-check",{"title":245,"path":246,"stem":247,"children":248,"page":6},"Advanced Go","\u002Fadvanced-go","6.advanced-go",[249,254,259,264,269,274,278,283,288],{"title":250,"path":251,"stem":252,"icon":253},"Advanced Go Roadmap","\u002Fadvanced-go\u002Fadvanced-roadmap","6.advanced-go\u002F1.advanced-roadmap","i-lucide-brain-circuit",{"title":255,"path":256,"stem":257,"icon":258},"Reflection","\u002Fadvanced-go\u002Freflection","6.advanced-go\u002F2.reflection","i-lucide-scan-search",{"title":260,"path":261,"stem":262,"icon":263},"Memory and Garbage Collection","\u002Fadvanced-go\u002Fmemory-and-garbage-collection","6.advanced-go\u002F3.memory-and-garbage-collection","i-lucide-memory-stick",{"title":265,"path":266,"stem":267,"icon":268},"Benchmarking and Profiling","\u002Fadvanced-go\u002Fbenchmarking-and-profiling","6.advanced-go\u002F4.benchmarking-and-profiling","i-lucide-gauge",{"title":270,"path":271,"stem":272,"icon":273},"Advanced Testing and Fuzzing","\u002Fadvanced-go\u002Fadvanced-testing-and-fuzzing","6.advanced-go\u002F5.advanced-testing-and-fuzzing","i-lucide-microscope",{"title":275,"path":276,"stem":277,"icon":48},"Advanced Concurrency","\u002Fadvanced-go\u002Fadvanced-concurrency","6.advanced-go\u002F6.advanced-concurrency",{"title":279,"path":280,"stem":281,"icon":282},"Unsafe and C Boundaries","\u002Fadvanced-go\u002Funsafe-and-cgo","6.advanced-go\u002F7.unsafe-and-cgo","i-lucide-radiation",{"title":284,"path":285,"stem":286,"icon":287},"Package and API Design","\u002Fadvanced-go\u002Fpackage-and-api-design","6.advanced-go\u002F8.package-and-api-design","i-lucide-boxes",{"title":289,"path":290,"stem":291,"icon":292},"Distributed Reliability","\u002Fadvanced-go\u002Fdistributed-reliability","6.advanced-go\u002F9.distributed-reliability","i-lucide-cloud-cog",{"title":294,"path":295,"stem":296,"children":297,"page":6},"Projects","\u002Fprojects","7.projects",[298,316,332,347],{"title":299,"path":300,"stem":301,"children":302,"icon":305},"CLI Task Manager","\u002Fprojects\u002Fcli-task-manager","7.projects\u002F1.cli-task-manager\u002Findex",[303,306,311],{"title":304,"path":300,"stem":301,"icon":305},"Project — CLI Task Manager","i-lucide-list-todo",{"title":307,"path":308,"stem":309,"icon":310},"CLI — Domain and Storage","\u002Fprojects\u002Fcli-task-manager\u002Fdomain-and-storage","7.projects\u002F1.cli-task-manager\u002F1.domain-and-storage","i-lucide-save",{"title":312,"path":313,"stem":314,"icon":315},"CLI — Commands and Tests","\u002Fprojects\u002Fcli-task-manager\u002Fcommands-and-tests","7.projects\u002F1.cli-task-manager\u002F2.commands-and-tests","i-lucide-terminal",{"title":317,"path":318,"stem":319,"children":320,"icon":323},"Concurrent URL Checker","\u002Fprojects\u002Fconcurrent-url-checker","7.projects\u002F2.concurrent-url-checker\u002Findex",[321,324,328],{"title":322,"path":318,"stem":319,"icon":323},"Project — Concurrent URL Checker","i-lucide-radar",{"title":325,"path":326,"stem":327,"icon":128},"URL Checker — Worker Pipeline","\u002Fprojects\u002Fconcurrent-url-checker\u002Fworker-pipeline","7.projects\u002F2.concurrent-url-checker\u002F1.worker-pipeline",{"title":329,"path":330,"stem":331,"icon":173},"URL Checker — Cancellation and Tests","\u002Fprojects\u002Fconcurrent-url-checker\u002Fcancellation-and-tests","7.projects\u002F2.concurrent-url-checker\u002F2.cancellation-and-tests",{"title":333,"path":334,"stem":335,"children":336},"File-backed API","\u002Fprojects\u002Ffile-backed-api","7.projects\u002F3.file-backed-api\u002Findex",[337,339,343],{"title":338,"path":334,"stem":335},"File-backed notes API",{"title":340,"path":341,"stem":342},"File store and concurrency","\u002Fprojects\u002Ffile-backed-api\u002Ffile-store-and-concurrency","7.projects\u002F3.file-backed-api\u002F1.file-store-and-concurrency",{"title":344,"path":345,"stem":346},"HTTP layer and tests","\u002Fprojects\u002Ffile-backed-api\u002Fhttp-and-tests","7.projects\u002F3.file-backed-api\u002F2.http-and-tests",{"title":348,"path":349,"stem":350,"children":351},"Production REST API","\u002Fprojects\u002Fproduction-rest-api","7.projects\u002F4.production-rest-api\u002Findex",[352,354,358],{"title":353,"path":349,"stem":350},"Production REST API capstone",{"title":355,"path":356,"stem":357},"Persistence and authentication","\u002Fprojects\u002Fproduction-rest-api\u002Fpersistence-and-auth","7.projects\u002F4.production-rest-api\u002F1.persistence-and-auth",{"title":359,"path":360,"stem":361},"Operations and release","\u002Fprojects\u002Fproduction-rest-api\u002Foperations-and-release","7.projects\u002F4.production-rest-api\u002F2.operations-and-release",{"title":363,"path":364,"stem":365,"children":366,"page":6},"Meta","\u002Fmeta","99.meta",[367,372],{"title":368,"path":369,"stem":370,"icon":371},"About","\u002Fmeta\u002Fabout","99.meta\u002F1.about","i-lucide-info",{"title":373,"path":374,"stem":375,"icon":376},"Acknowledgements","\u002Fmeta\u002Facknowledgements","99.meta\u002F2.acknowledgements","i-lucide-heart-handshake",{"id":378,"title":26,"body":379,"description":1449,"extension":1450,"links":1451,"meta":1452,"navigation":1453,"path":27,"seo":1454,"stem":28,"__hash__":1456},"docs\u002F1.getting-started\u002F4.first-program.md",{"type":380,"value":381,"toc":1436},"minimark",[382,388,393,397,401,409,457,464,513,525,534,541,547,656,659,766,780,784,799,802,810,817,821,824,894,897,911,918,922,927,941,952,961,968,972,979,992,998,1007,1015,1021,1024,1037,1043,1055,1061,1064,1068,1072,1127,1131,1146,1381,1385,1411,1426,1429,1432],[383,384],"learning-lesson-meta",{"description":385,"difficulty":386,"prerequisites":21,"time":387},"Go from an empty folder to a working program, and learn what every line and command does.","Beginner","30 minutes",[389,390,392],"h2",{"id":391},"what-you-will-learn","What you will learn",[394,395,396],"p",{},"You will turn an empty folder into a working Go program, and you will understand every file and command involved. You will also break the program on purpose, because reading compiler errors is a skill you will use every day.",[389,398,400],{"id":399},"create-a-project","Create a project",[394,402,403,404,408],{},"Every Go project is a ",[405,406,407],"strong",{},"module",". Start by making a folder and initialising one:",[410,411,417],"pre",{"className":412,"code":413,"filename":414,"language":415,"meta":416,"style":416},"language-bash shiki shiki-themes solarized-light material-theme one-dark-pro","mkdir hello-go\ncd hello-go\ngo mod init example.com\u002Fhello-go\n","Terminal","bash","",[418,419,420,433,442],"code",{"__ignoreMap":416},[421,422,425,429],"span",{"class":423,"line":424},"line",1,[421,426,428],{"class":427},"sqRHY","mkdir",[421,430,432],{"class":431},"sVazx"," hello-go\n",[421,434,436,440],{"class":423,"line":435},2,[421,437,439],{"class":438},"sTZgv","cd",[421,441,432],{"class":431},[421,443,445,448,451,454],{"class":423,"line":444},3,[421,446,447],{"class":427},"go",[421,449,450],{"class":431}," mod",[421,452,453],{"class":431}," init",[421,455,456],{"class":431}," example.com\u002Fhello-go\n",[394,458,459,460,463],{},"The last command creates one file, ",[418,461,462],{},"go.mod",". Open it:",[410,465,468],{"className":466,"code":467,"filename":462,"language":447,"meta":416,"style":416},"language-go shiki shiki-themes solarized-light material-theme one-dark-pro","module example.com\u002Fhello-go\n\ngo 1.26\n",[418,469,470,499,505],{"__ignoreMap":416},[421,471,472,475,478,482,485,489,492,495],{"class":423,"line":424},[421,473,407],{"class":474},"s45-6",[421,476,477],{"class":474}," example",[421,479,481],{"class":480},"shFME",".",[421,483,484],{"class":474},"com",[421,486,488],{"class":487},"sEOdo","\u002F",[421,490,491],{"class":474},"hello",[421,493,494],{"class":487},"-",[421,496,498],{"class":497},"s7Bcg","go\n",[421,500,501],{"class":423,"line":435},[421,502,504],{"emptyLinePlaceholder":503},true,"\n",[421,506,507,509],{"class":423,"line":444},[421,508,447],{"class":497},[421,510,512],{"class":511},"sAJzr"," 1.26\n",[394,514,515,516,518,519,521,522,524],{},"The ",[418,517,407],{}," line is the name of your project. It also becomes the prefix for import paths if you split your code into packages later. The ",[418,520,447],{}," line records which Go version the project targets, and yours will match the version you installed. As you add third-party libraries, ",[418,523,462],{}," will also list them.",[394,526,527,530,531,481],{},[418,528,529],{},"example.com\u002Fhello-go"," is a placeholder, which is fine for practice. For a project you plan to publish, use its real repository path, such as ",[418,532,533],{},"github.com\u002Fyourname\u002Fhello-go",[389,535,537,538],{"id":536},"write-maingo","Write ",[418,539,540],{},"main.go",[394,542,543,544,546],{},"Create a file named ",[418,545,540],{}," in the same folder:",[410,548,550],{"className":466,"code":549,"filename":540,"language":447,"meta":416,"style":416},"package main\n\nimport \"fmt\"\n\nfunc main() {\n    name := \"Gopher\"\n    fmt.Println(\"Hello,\", name)\n}\n",[418,551,552,561,565,581,586,602,619,650],{"__ignoreMap":416},[421,553,554,557],{"class":423,"line":424},[421,555,556],{"class":487},"package",[421,558,560],{"class":559},"snwKR"," main\n",[421,562,563],{"class":423,"line":435},[421,564,504],{"emptyLinePlaceholder":503},[421,566,567,570,574,578],{"class":423,"line":444},[421,568,569],{"class":497},"import",[421,571,573],{"class":572},"sED5a"," \"",[421,575,577],{"class":576},"sdLNw","fmt",[421,579,580],{"class":572},"\"\n",[421,582,584],{"class":423,"line":583},4,[421,585,504],{"emptyLinePlaceholder":503},[421,587,589,592,596,599],{"class":423,"line":588},5,[421,590,591],{"class":487},"func",[421,593,595],{"class":594},"sisdC"," main",[421,597,598],{"class":480},"()",[421,600,601],{"class":480}," {\n",[421,603,605,608,612,614,617],{"class":423,"line":604},6,[421,606,607],{"class":474},"    name",[421,609,611],{"class":610},"su2KV"," :=",[421,613,573],{"class":572},[421,615,616],{"class":431},"Gopher",[421,618,580],{"class":572},[421,620,622,625,627,630,633,636,639,641,644,647],{"class":423,"line":621},7,[421,623,624],{"class":474},"    fmt",[421,626,481],{"class":480},[421,628,629],{"class":594},"Println",[421,631,632],{"class":480},"(",[421,634,635],{"class":572},"\"",[421,637,638],{"class":431},"Hello,",[421,640,635],{"class":572},[421,642,643],{"class":480},",",[421,645,646],{"class":474}," name",[421,648,649],{"class":480},")\n",[421,651,653],{"class":423,"line":652},8,[421,654,655],{"class":480},"}\n",[394,657,658],{},"Now read it one line at a time:",[660,661,662,675],"table",{},[663,664,665],"thead",{},[666,667,668,672],"tr",{},[669,670,671],"th",{},"Line",[669,673,674],{},"Meaning",[676,677,678,693,706,719,740,756],"tbody",{},[666,679,680,686],{},[681,682,683],"td",{},[418,684,685],{},"package main",[681,687,688,689,692],{},"Every Go file belongs to a package. The package named ",[418,690,691],{},"main"," is special: it tells Go to build an executable program rather than a library.",[666,694,695,700],{},[681,696,697],{},[418,698,699],{},"import \"fmt\"",[681,701,702,703,705],{},"Brings in the standard library package ",[418,704,577],{}," (short for \"format\"), which handles printing text.",[666,707,708,713],{},[681,709,710],{},[418,711,712],{},"func main() {",[681,714,715,716,718],{},"Declares a function named ",[418,717,691],{},". When a program starts, Go runs this function first.",[666,720,721,726],{},[681,722,723],{},[418,724,725],{},"name := \"Gopher\"",[681,727,728,729,732,733,736,737,481],{},"Creates a variable called ",[418,730,731],{},"name"," holding the text ",[418,734,735],{},"\"Gopher\"",". Go works out that it is a ",[418,738,739],{},"string",[666,741,742,747],{},[681,743,744],{},[418,745,746],{},"fmt.Println(\"Hello,\", name)",[681,748,749,750,752,753,755],{},"Calls the ",[418,751,629],{}," function from ",[418,754,577],{},". It prints its arguments separated by spaces, then a newline.",[666,757,758,763],{},[681,759,760],{},[418,761,762],{},"}",[681,764,765],{},"Ends the function.",[394,767,768,769,771,772,775,776,779],{},"Notice that ",[418,770,629],{}," starts with a capital letter. In Go, a capital first letter means a name is visible outside its package. That is why you can call ",[418,773,774],{},"fmt.Println"," but could not call a hypothetical ",[418,777,778],{},"fmt.println",". You will see this rule again in the packages lesson.",[389,781,783],{"id":782},"run-it","Run it",[410,785,787],{"className":412,"code":786,"filename":414,"language":415,"meta":416,"style":416},"go run .\n",[418,788,789],{"__ignoreMap":416},[421,790,791,793,796],{"class":423,"line":424},[421,792,447],{"class":427},[421,794,795],{"class":431}," run",[421,797,798],{"class":431}," .\n",[394,800,801],{},"You should see:",[410,803,808],{"className":804,"code":806,"language":807,"meta":416},[805],"language-text","Hello, Gopher\n","text",[418,809,806],{"__ignoreMap":416},[394,811,812,813,816],{},"The dot means \"the package in the current folder\". Behind the scenes, ",[418,814,815],{},"go run"," compiles your code into a temporary executable, runs it, and deletes it. It is the command you will use most while learning.",[389,818,820],{"id":819},"format-it","Format it",[394,822,823],{},"Go has one official code style, applied by a tool. Make your code messy on purpose:",[410,825,827],{"className":466,"code":826,"filename":540,"language":447,"meta":416,"style":416},"package main\nimport \"fmt\"\nfunc main(){\nname:=\"Gopher\"\n        fmt.Println(\"Hello,\",name)\n}\n",[418,828,829,835,845,854,867,890],{"__ignoreMap":416},[421,830,831,833],{"class":423,"line":424},[421,832,556],{"class":487},[421,834,560],{"class":559},[421,836,837,839,841,843],{"class":423,"line":435},[421,838,569],{"class":497},[421,840,573],{"class":572},[421,842,577],{"class":576},[421,844,580],{"class":572},[421,846,847,849,851],{"class":423,"line":444},[421,848,591],{"class":487},[421,850,595],{"class":594},[421,852,853],{"class":480},"(){\n",[421,855,856,858,861,863,865],{"class":423,"line":583},[421,857,731],{"class":474},[421,859,860],{"class":610},":=",[421,862,635],{"class":572},[421,864,616],{"class":431},[421,866,580],{"class":572},[421,868,869,872,874,876,878,880,882,884,886,888],{"class":423,"line":588},[421,870,871],{"class":474},"        fmt",[421,873,481],{"class":480},[421,875,629],{"class":594},[421,877,632],{"class":480},[421,879,635],{"class":572},[421,881,638],{"class":431},[421,883,635],{"class":572},[421,885,643],{"class":480},[421,887,731],{"class":474},[421,889,649],{"class":480},[421,891,892],{"class":423,"line":604},[421,893,655],{"class":480},[394,895,896],{},"Then run:",[410,898,900],{"className":412,"code":899,"filename":414,"language":415,"meta":416,"style":416},"go fmt .\n",[418,901,902],{"__ignoreMap":416},[421,903,904,906,909],{"class":423,"line":424},[421,905,447],{"class":427},[421,907,908],{"class":431}," fmt",[421,910,798],{"class":431},[394,912,913,914,917],{},"The file is rewritten with consistent tabs, spacing, and line breaks. This is why Go projects look alike. There are no style arguments, and you never format by hand. If you ever need to format a single file, ",[418,915,916],{},"gofmt -w main.go"," does the same job. With the editor setup from the previous lesson, this happens every time you save.",[389,919,921],{"id":920},"build-an-executable","Build an executable",[394,923,924,926],{},[418,925,815],{}," throws its executable away. When you want to keep one, use:",[410,928,930],{"className":412,"code":929,"filename":414,"language":415,"meta":416,"style":416},"go build .\n",[418,931,932],{"__ignoreMap":416},[421,933,934,936,939],{"class":423,"line":424},[421,935,447],{"class":427},[421,937,938],{"class":431}," build",[421,940,798],{"class":431},[394,942,943,944,947,948,951],{},"This creates a file named after your module folder: ",[418,945,946],{},"hello-go"," on macOS and Linux, ",[418,949,950],{},"hello-go.exe"," on Windows. Run it directly:",[410,953,955],{"className":412,"code":954,"filename":414,"language":415,"meta":416,"style":416},".\u002Fhello-go\n",[418,956,957],{"__ignoreMap":416},[421,958,959],{"class":423,"line":424},[421,960,954],{"class":427},[394,962,963,964,967],{},"On Windows use ",[418,965,966],{},".\\hello-go.exe",". You can copy that single file to another machine with the same operating system and processor, and it runs without Go installed.",[389,969,971],{"id":970},"break-it-on-purpose","Break it on purpose",[394,973,974,975,978],{},"Compiler errors are Go's way of helping you. Try each of these changes, run ",[418,976,977],{},"go run .",", and read the message. Then undo the change.",[394,980,981,984,985,987,988,991],{},[405,982,983],{},"A typo in a function name."," Change ",[418,986,629],{}," to ",[418,989,990],{},"PrintLn",":",[410,993,996],{"className":994,"code":995,"language":807,"meta":416},[805],".\u002Fmain.go:7:6: undefined: fmt.PrintLn\n",[418,997,995],{"__ignoreMap":416},[394,999,1000,1001,1003,1004,1006],{},"The message gives the file, line, and column, then the problem. Go is case-sensitive, so ",[418,1002,990],{}," and ",[418,1005,629],{}," are different names.",[394,1008,1009,1012,1013,991],{},[405,1010,1011],{},"A missing import."," Delete the line ",[418,1014,699],{},[410,1016,1019],{"className":1017,"code":1018,"language":807,"meta":416},[805],".\u002Fmain.go:6:2: undefined: fmt\n",[418,1020,1018],{"__ignoreMap":416},[394,1022,1023],{},"You used a package you never imported.",[394,1025,1026,1029,1030,1033,1034,1036],{},[405,1027,1028],{},"An unused import."," Add ",[418,1031,1032],{},"import \"os\""," below the ",[418,1035,577],{}," import without using it:",[410,1038,1041],{"className":1039,"code":1040,"language":807,"meta":416},[805],".\u002Fmain.go:5:2: \"os\" imported and not used\n",[418,1042,1040],{"__ignoreMap":416},[394,1044,1045,1029,1048,1051,1052,1054],{},[405,1046,1047],{},"An unused variable.",[418,1049,1050],{},"count := 3"," inside ",[418,1053,691],{}," and never use it:",[410,1056,1059],{"className":1057,"code":1058,"language":807,"meta":416},[805],".\u002Fmain.go:8:2: declared and not used: count\n",[418,1060,1058],{"__ignoreMap":416},[394,1062,1063],{},"These last two surprise newcomers. Go treats unused imports and variables as errors, not warnings. It feels strict, but it keeps code free of leftovers.",[1065,1066,1067],"tip",{},"Read the first error first, and fix it before looking at the others. Later errors are often caused by the first one, and fixing it can make several disappear.",[389,1069,1071],{"id":1070},"common-mistakes","Common mistakes",[1073,1074,1075,1087,1100,1115],"ul",{},[1076,1077,1078,1083,1084,481],"li",{},[405,1079,1080,481],{},[418,1081,1082],{},"go: go.mod file not found"," You ran a Go command outside a module. Change into the project folder or run ",[418,1085,1086],{},"go mod init",[1076,1088,1089,1096,1097,1099],{},[405,1090,1091,1092,1095],{},"Running ",[418,1093,1094],{},"go run main.go"," and getting confused by multiple files."," Use ",[418,1098,977],{}," so Go builds the whole package, not one file.",[1076,1101,1102,1107,1108,1111,1112,1114],{},[405,1103,1104,1105,481],{},"A package name other than ",[418,1106,691],{}," If the file says ",[418,1109,1110],{},"package hello",", Go builds a library and ",[418,1113,815],{}," fails, because there is nothing to execute.",[1076,1116,1117,1123,1124,481],{},[405,1118,1119,1120,1122],{},"Forgetting that ",[418,1121,691],{}," must be lowercase."," Go looks for exactly ",[418,1125,1126],{},"func main()",[389,1128,1130],{"id":1129},"practice","Practice",[394,1132,1133,1134,1137,1138,1141,1142,1145],{},"Create variables for your name, the language you are learning, and the number of days you have studied. Print one readable sentence using all three. Then print the same sentence again using ",[418,1135,1136],{},"fmt.Printf"," with ",[418,1139,1140],{},"%s"," for strings and ",[418,1143,1144],{},"%d"," for the integer.",[1147,1148,1149],"accordion",{},[1150,1151,1154,1341,1344,1350],"accordion-item",{"icon":1152,"label":1153},"i-lucide-lightbulb","Show solution",[410,1155,1157],{"className":466,"code":1156,"filename":540,"language":447,"meta":416,"style":416},"package main\n\nimport \"fmt\"\n\nfunc main() {\n    name := \"Asha\"\n    language := \"Go\"\n    days := 3\n\n    fmt.Println(name, \"has studied\", language, \"for\", days, \"days\")\n    fmt.Printf(\"%s has studied %s for %d days\\n\", name, language, days)\n}\n",[418,1158,1159,1165,1169,1179,1183,1193,1206,1220,1230,1235,1287,1336],{"__ignoreMap":416},[421,1160,1161,1163],{"class":423,"line":424},[421,1162,556],{"class":487},[421,1164,560],{"class":559},[421,1166,1167],{"class":423,"line":435},[421,1168,504],{"emptyLinePlaceholder":503},[421,1170,1171,1173,1175,1177],{"class":423,"line":444},[421,1172,569],{"class":497},[421,1174,573],{"class":572},[421,1176,577],{"class":576},[421,1178,580],{"class":572},[421,1180,1181],{"class":423,"line":583},[421,1182,504],{"emptyLinePlaceholder":503},[421,1184,1185,1187,1189,1191],{"class":423,"line":588},[421,1186,591],{"class":487},[421,1188,595],{"class":594},[421,1190,598],{"class":480},[421,1192,601],{"class":480},[421,1194,1195,1197,1199,1201,1204],{"class":423,"line":604},[421,1196,607],{"class":474},[421,1198,611],{"class":610},[421,1200,573],{"class":572},[421,1202,1203],{"class":431},"Asha",[421,1205,580],{"class":572},[421,1207,1208,1211,1213,1215,1218],{"class":423,"line":621},[421,1209,1210],{"class":474},"    language",[421,1212,611],{"class":610},[421,1214,573],{"class":572},[421,1216,1217],{"class":431},"Go",[421,1219,580],{"class":572},[421,1221,1222,1225,1227],{"class":423,"line":652},[421,1223,1224],{"class":474},"    days",[421,1226,611],{"class":610},[421,1228,1229],{"class":511}," 3\n",[421,1231,1233],{"class":423,"line":1232},9,[421,1234,504],{"emptyLinePlaceholder":503},[421,1236,1238,1240,1242,1244,1246,1248,1250,1252,1255,1257,1259,1262,1264,1266,1269,1271,1273,1276,1278,1280,1283,1285],{"class":423,"line":1237},10,[421,1239,624],{"class":474},[421,1241,481],{"class":480},[421,1243,629],{"class":594},[421,1245,632],{"class":480},[421,1247,731],{"class":474},[421,1249,643],{"class":480},[421,1251,573],{"class":572},[421,1253,1254],{"class":431},"has studied",[421,1256,635],{"class":572},[421,1258,643],{"class":480},[421,1260,1261],{"class":474}," language",[421,1263,643],{"class":480},[421,1265,573],{"class":572},[421,1267,1268],{"class":431},"for",[421,1270,635],{"class":572},[421,1272,643],{"class":480},[421,1274,1275],{"class":474}," days",[421,1277,643],{"class":480},[421,1279,573],{"class":572},[421,1281,1282],{"class":431},"days",[421,1284,635],{"class":572},[421,1286,649],{"class":480},[421,1288,1290,1292,1294,1297,1299,1301,1304,1307,1309,1312,1314,1316,1320,1322,1324,1326,1328,1330,1332,1334],{"class":423,"line":1289},11,[421,1291,624],{"class":474},[421,1293,481],{"class":480},[421,1295,1296],{"class":594},"Printf",[421,1298,632],{"class":480},[421,1300,635],{"class":572},[421,1302,1140],{"class":1303},"st3jj",[421,1305,1306],{"class":431}," has studied ",[421,1308,1140],{"class":1303},[421,1310,1311],{"class":431}," for ",[421,1313,1144],{"class":1303},[421,1315,1275],{"class":431},[421,1317,1319],{"class":1318},"sk51v","\\n",[421,1321,635],{"class":572},[421,1323,643],{"class":480},[421,1325,646],{"class":474},[421,1327,643],{"class":480},[421,1329,1261],{"class":474},[421,1331,643],{"class":480},[421,1333,1275],{"class":474},[421,1335,649],{"class":480},[421,1337,1339],{"class":423,"line":1338},12,[421,1340,655],{"class":480},[394,1342,1343],{},"Output:",[410,1345,1348],{"className":1346,"code":1347,"language":807,"meta":416},[805],"Asha has studied Go for 3 days\nAsha has studied Go for 3 days\n",[418,1349,1347],{"__ignoreMap":416},[394,1351,1352,1354,1355,1357,1358,1003,1360,1362,1363,1365,1366,1368,1369,1371,1372,987,1374,1376,1377,1380],{},[418,1353,629],{}," joins its arguments with spaces and adds a newline. ",[418,1356,1296],{}," takes a template where ",[418,1359,1140],{},[418,1361,1144],{}," are placeholders filled in from the arguments that follow, in order. Unlike ",[418,1364,629],{},", ",[418,1367,1296],{}," does not add a newline, so the template ends with ",[418,1370,1319],{},". Try changing ",[418,1373,1144],{},[418,1375,1140],{}," and run ",[418,1378,1379],{},"go vet ."," to see Go warn you about the mismatch.",[389,1382,1384],{"id":1383},"summary","Summary",[394,1386,1387,1388,1390,1391,1393,1394,1396,1397,1399,1400,1402,1403,1406,1407,1410],{},"A Go project is a module, created with ",[418,1389,1086],{},", which produces a ",[418,1392,462],{}," file. An executable starts in ",[418,1395,685],{}," at ",[418,1398,1126],{},". Use ",[418,1401,977],{}," to try your code, ",[418,1404,1405],{},"go fmt ."," to format it, and ",[418,1408,1409],{},"go build ."," to produce a file you can keep. Compiler errors point to an exact file, line, and problem, and reading them carefully is part of the normal edit cycle.",[394,1412,1413,1414,1003,1421,481],{},"Official references: ",[1415,1416,1420],"a",{"href":1417,"rel":1418},"https:\u002F\u002Fgo.dev\u002Fdoc\u002Fcode",[1419],"nofollow","How to write Go code",[1415,1422,1425],{"href":1423,"rel":1424},"https:\u002F\u002Fgo.dev\u002Fdoc\u002Ftutorial\u002Fgetting-started",[1419],"Tutorial: Get started with Go",[1427,1428],"learning-lesson-complete",{},[1430,1431],"learning-lesson-navigation",{"next":32,"nextTitle":31,"previous":22,"previousTitle":21},[1433,1434,1435],"style",{},"html pre.shiki code .sqRHY, html code.shiki .sqRHY{--shiki-light:#268BD2;--shiki-default:#FFCB6B;--shiki-dark:#61AFEF}html pre.shiki code .sVazx, html code.shiki .sVazx{--shiki-light:#2AA198;--shiki-default:#C3E88D;--shiki-dark:#98C379}html pre.shiki code .sTZgv, html code.shiki .sTZgv{--shiki-light:#268BD2;--shiki-default:#82AAFF;--shiki-dark:#56B6C2}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s45-6, html code.shiki .s45-6{--shiki-light:#268BD2;--shiki-default:#EEFFFF;--shiki-dark:#E06C75}html pre.shiki code .shFME, html code.shiki .shFME{--shiki-light:#657B83;--shiki-default:#89DDFF;--shiki-dark:#ABB2BF}html pre.shiki code .sEOdo, html code.shiki .sEOdo{--shiki-light:#859900;--shiki-default:#89DDFF;--shiki-dark:#C678DD}html pre.shiki code .s7Bcg, html code.shiki .s7Bcg{--shiki-light:#859900;--shiki-light-font-style:inherit;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#C678DD;--shiki-dark-font-style:inherit}html pre.shiki code .sAJzr, html code.shiki .sAJzr{--shiki-light:#D33682;--shiki-default:#F78C6C;--shiki-dark:#D19A66}html pre.shiki code .snwKR, html code.shiki .snwKR{--shiki-light:#CB4B16;--shiki-default:#FFCB6B;--shiki-dark:#E5C07B}html pre.shiki code .sED5a, html code.shiki .sED5a{--shiki-light:#2AA198;--shiki-default:#89DDFF;--shiki-dark:#98C379}html pre.shiki code .sdLNw, html code.shiki .sdLNw{--shiki-light:#2AA198;--shiki-default:#FFCB6B;--shiki-dark:#98C379}html pre.shiki code .sisdC, html code.shiki .sisdC{--shiki-light:#268BD2;--shiki-default:#82AAFF;--shiki-dark:#61AFEF}html pre.shiki code .su2KV, html code.shiki .su2KV{--shiki-light:#859900;--shiki-default:#89DDFF;--shiki-dark:#E5C07B}html pre.shiki code .st3jj, html code.shiki .st3jj{--shiki-light:#CB4B16;--shiki-default:#F07178;--shiki-dark:#D19A66}html pre.shiki code .sk51v, html code.shiki .sk51v{--shiki-light:#CB4B16;--shiki-default:#EEFFFF;--shiki-dark:#56B6C2}",{"title":416,"searchDepth":435,"depth":435,"links":1437},[1438,1439,1440,1442,1443,1444,1445,1446,1447,1448],{"id":391,"depth":435,"text":392},{"id":399,"depth":435,"text":400},{"id":536,"depth":435,"text":1441},"Write main.go",{"id":782,"depth":435,"text":783},{"id":819,"depth":435,"text":820},{"id":920,"depth":435,"text":921},{"id":970,"depth":435,"text":971},{"id":1070,"depth":435,"text":1071},{"id":1129,"depth":435,"text":1130},{"id":1383,"depth":435,"text":1384},"Create a module, write and run a Go program, format it, build it, and learn to read compiler errors.","md",null,{},{"icon":29},{"description":1455,"title":26},"Write your first Go program step by step and learn what go mod init, package main, import, func main, go run, go build, and gofmt do.","4A9RTXSkmmONVTMi6P3YlVXfzpodrnoH3jE_f1Un7A8",[1458,1460],{"title":21,"path":22,"stem":23,"description":1459,"icon":24,"children":-1},"Install Go on Windows, macOS, or Linux, verify it works, fix PATH problems, and set up your editor.",{"title":31,"path":32,"stem":33,"description":1461,"icon":34,"children":-1},"Understand packages and modules, split code into your own packages, and add and remove third-party libraries.",1794118096030]