[{"data":1,"prerenderedAt":2237},["ShallowReactive",2],{"blog-golang-getting-started":3},{"id":4,"title":5,"body":6,"date":2220,"description":2221,"draft":2222,"extension":2223,"image":2224,"meta":2225,"navigation":274,"path":2226,"seo":2227,"stem":2228,"tags":2229,"__hash__":2236},"blogs\u002Fblogs\u002Fgolang-getting-started\u002Findex.md","Getting started with Golang",{"type":7,"value":8,"toc":2205},"minimark",[9,13,20,23,36,39,42,45,51,56,202,206,372,385,854,858,869,876,879,884,922,926,929,932,952,959,1075,1087,1091,1096,1103,1110,1115,1147,1150,1153,1210,1214,1224,1227,1290,1294,1297,1342,1349,1352,1427,1430,1503,1506,1513,1587,1589,1607,1611,1621,1674,1677,1737,1740,1791,1795,1808,1874,1878,1881,1942,1945,2061,2065,2079,2141,2152,2159,2162,2165,2168,2198,2201],[10,11,12],"p",{},"Go is a simple, fast, and concurrent programming language. Its simplicity in design makes it an amazing programming language to work with. Go is currently gaining a lot of popularity, and a lot of organizations now prefer to write their backend in Go.",[10,14,15],{},[16,17],"img",{"alt":18,"src":19},"go logo","\u002Fimages\u002Fblogs\u002Fgolang-getting-started\u002Fgo-logo.png",[10,21,22],{},"Go was designed at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson to improve programming productivity in an era of multicore, networked machines and large codebases.The designers wanted to address criticisms of other languages in use at Google, but keep their useful characteristics:",[24,25,26,30,33],"ul",{},[27,28,29],"li",{},"Static typing and run-time efficiency (like C)",[27,31,32],{},"Readability and usability (like Python)",[27,34,35],{},"High-performance networking and multiprocessing",[10,37,38],{},"Its designers were primarily motivated by their shared dislike of C++.",[10,40,41],{},"Go was publicly announced in November 2009,and version 1.0 was released in March 2012. Go is widely used in production at Google and in many other organizations and open-source projects like Kubernetes, Prometheus, and Docker.",[10,43,44],{},"In retrospect the Go authors judged Go to be successful due to the overall engineering work around the language, including the runtime support for the language's concurrency feature.",[46,47,48],"blockquote",{},[10,49,50],{},"Although the design of most languages concentrates on innovations in syntax, semantics, or typing, Go is focused on the software development process itself. The principal unusual property of the language itself—concurrency—addressed problems that arose with the proliferation of multicore CPUs in the 2010s. But more significant was the early work that established fundamentals for packaging, dependencies, build, test, deployment, and other workaday tasks of the software development world, aspects that are not usually foremost in language design.",[52,53,55],"h2",{"id":54},"go-installation-for-linux","Go Installation for linux",[57,58,59,69,102,129,167],"ol",{},[27,60,61,68],{},[62,63,67],"a",{"href":64,"rel":65},"https:\u002F\u002Fgo.dev\u002Fdoc\u002Finstall",[66],"nofollow","Download"," Binary",[27,70,71,72],{},"Remove old go version (if any)\n",[73,74,79],"pre",{"className":75,"code":76,"language":77,"meta":78,"style":78},"language-bash shiki shiki-themes github-light","sudo rm -rf \u002Fusr\u002Flocal\u002Fgo\n","bash","",[80,81,82],"code",{"__ignoreMap":78},[83,84,87,91,95,99],"span",{"class":85,"line":86},"line",1,[83,88,90],{"class":89},"s7eDp","sudo",[83,92,94],{"class":93},"sYBdl"," rm",[83,96,98],{"class":97},"sYu0t"," -rf",[83,100,101],{"class":93}," \u002Fusr\u002Flocal\u002Fgo\n",[27,103,104,105],{},"Install go binary\n",[73,106,108],{"className":75,"code":107,"language":77,"meta":78,"style":78},"sudo tar -C \u002Fusr\u002Flocal -xzf go1.24.2.linux-amd64.tar.gz\n",[80,109,110],{"__ignoreMap":78},[83,111,112,114,117,120,123,126],{"class":85,"line":86},[83,113,90],{"class":89},[83,115,116],{"class":93}," tar",[83,118,119],{"class":97}," -C",[83,121,122],{"class":93}," \u002Fusr\u002Flocal",[83,124,125],{"class":97}," -xzf",[83,127,128],{"class":93}," go1.24.2.linux-amd64.tar.gz\n",[27,130,131,132],{},"Add \u002Fusr\u002Flocal\u002Fgo\u002Fbin to the PATH environment variable\n",[73,133,135],{"className":75,"code":134,"language":77,"meta":78,"style":78},"echo \"export PATH=$PATH:\u002Fusr\u002Flocal\u002Fgo\u002Fbin\" >> ~\u002F.bashrc\nsource ~\u002F.bashrc\n",[80,136,137,159],{"__ignoreMap":78},[83,138,139,142,145,149,152,156],{"class":85,"line":86},[83,140,141],{"class":97},"echo",[83,143,144],{"class":93}," \"export PATH=",[83,146,148],{"class":147},"sgsFI","$PATH",[83,150,151],{"class":93},":\u002Fusr\u002Flocal\u002Fgo\u002Fbin\"",[83,153,155],{"class":154},"sD7c4"," >>",[83,157,158],{"class":93}," ~\u002F.bashrc\n",[83,160,162,165],{"class":85,"line":161},2,[83,163,164],{"class":97},"source",[83,166,158],{"class":93},[27,168,169,170,183,184],{},"Verify installation\n",[73,171,173],{"className":75,"code":172,"language":77,"meta":78,"style":78},"go version\n",[80,174,175],{"__ignoreMap":78},[83,176,177,180],{"class":85,"line":86},[83,178,179],{"class":89},"go",[83,181,182],{"class":93}," version\n","\nOutputs:\n",[73,185,187],{"className":75,"code":186,"language":77,"meta":78,"style":78},"go version go1.23.1 linux\u002Famd64\n",[80,188,189],{"__ignoreMap":78},[83,190,191,193,196,199],{"class":85,"line":86},[83,192,179],{"class":89},[83,194,195],{"class":93}," version",[83,197,198],{"class":93}," go1.23.1",[83,200,201],{"class":93}," linux\u002Famd64\n",[52,203,205],{"id":204},"lets-write-some-code","Let's write some code",[57,207,208,231,252,340],{},[27,209,210,211],{},"Make a directory\n",[73,212,214],{"className":75,"code":213,"language":77,"meta":78,"style":78},"mkdir go-example\ncd go-example\n",[80,215,216,224],{"__ignoreMap":78},[83,217,218,221],{"class":85,"line":86},[83,219,220],{"class":89},"mkdir",[83,222,223],{"class":93}," go-example\n",[83,225,226,229],{"class":85,"line":161},[83,227,228],{"class":97},"cd",[83,230,223],{"class":93},[27,232,233,234],{},"Enable dependecy tracking\n",[73,235,237],{"className":75,"code":236,"language":77,"meta":78,"style":78},"go mod init example\u002Fhello\n",[80,238,239],{"__ignoreMap":78},[83,240,241,243,246,249],{"class":85,"line":86},[83,242,179],{"class":89},[83,244,245],{"class":93}," mod",[83,247,248],{"class":93}," init",[83,250,251],{"class":93}," example\u002Fhello\n",[27,253,254,255,258,259,305,306],{},"Create a file ",[80,256,257],{},"hello.go"," in which to write our code.\n",[73,260,263],{"className":261,"code":262,"language":179,"meta":78,"style":78},"language-go shiki shiki-themes github-light","package main\n\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hello, World!\")\n}\n",[80,264,265,270,276,282,287,293,299],{"__ignoreMap":78},[83,266,267],{"class":85,"line":86},[83,268,269],{},"package main\n",[83,271,272],{"class":85,"line":161},[83,273,275],{"emptyLinePlaceholder":274},true,"\n",[83,277,279],{"class":85,"line":278},3,[83,280,281],{},"import \"fmt\"\n",[83,283,285],{"class":85,"line":284},4,[83,286,275],{"emptyLinePlaceholder":274},[83,288,290],{"class":85,"line":289},5,[83,291,292],{},"func main() {\n",[83,294,296],{"class":85,"line":295},6,[83,297,298],{},"    fmt.Println(\"Hello, World!\")\n",[83,300,302],{"class":85,"line":301},7,[83,303,304],{},"}\n","\nIn this code, we:\n",[24,307,308,315,328],{},[27,309,310,311,314],{},"Declare a ",[80,312,313],{},"main"," package (a package is a way to group functions, and it's made up of all the files in the same directory).",[27,316,317,318,321,322,327],{},"Import the popular ",[80,319,320],{},"fmt"," package, which contains functions for formatting text, including printing to the console. This package is one of the ",[62,323,326],{"href":324,"rel":325},"https:\u002F\u002Fpkg.go.dev\u002Fstd",[66],"standard library packages"," we got when we installed Go.",[27,329,330,331,333,334,336,337,339],{},"Implement a ",[80,332,313],{}," function to print a message to the console. A ",[80,335,313],{}," function executes by default when we run the ",[80,338,313],{}," package.",[27,341,342,343,358,359],{},"Run the code\n",[73,344,346],{"className":75,"code":345,"language":77,"meta":78,"style":78},"go run hello.go\n",[80,347,348],{"__ignoreMap":78},[83,349,350,352,355],{"class":85,"line":86},[83,351,179],{"class":89},[83,353,354],{"class":93}," run",[83,356,357],{"class":93}," hello.go\n","\nOutput:\n",[73,360,362],{"className":75,"code":361,"language":77,"meta":78,"style":78},"Hello, World!\n",[80,363,364],{"__ignoreMap":78},[83,365,366,369],{"class":85,"line":86},[83,367,368],{"class":89},"Hello,",[83,370,371],{"class":93}," World!\n",[46,373,374],{},[10,375,376,377,380,381,384],{},"The ",[80,378,379],{},"go run"," command is one of many go commands we'll use to get things done with Go. Use the ",[80,382,383],{},"go help"," command to get a list of the others:",[73,386,388],{"className":75,"code":387,"language":77,"meta":78,"style":78},"govind@debian:~$ go help\nGo is a tool for managing Go source code.\n\nUsage:\n\n    go \u003Ccommand> [arguments]\n\nThe commands are:\n\n    bug         start a bug report\n    build       compile packages and dependencies\n    clean       remove object files and cached files\n    doc         show documentation for package or symbol\n    env         print Go environment information\n    fix         update packages to use new APIs\n    fmt         gofmt (reformat) package sources\n    generate    generate Go files by processing source\n    get         add dependencies to current module and install them\n    install     compile and install packages and dependencies\n    list        list packages or modules\n    mod         module maintenance\n    work        workspace maintenance\n    run         compile and run Go program\n    telemetry   manage telemetry data and settings\n    test        test packages\n    tool        run specified go tool\n    version     print Go version\n    vet         report likely mistakes in packages\n\nUse \"go help \u003Ccommand>\" for more information about a command.\n",[80,389,390,401,430,434,439,443,463,467,479,484,501,519,542,565,582,605,617,638,666,685,701,713,724,742,762,774,791,804,824,829],{"__ignoreMap":78},[83,391,392,395,398],{"class":85,"line":86},[83,393,394],{"class":89},"govind@debian:~$",[83,396,397],{"class":93}," go",[83,399,400],{"class":93}," help\n",[83,402,403,406,409,412,415,418,421,424,427],{"class":85,"line":161},[83,404,405],{"class":89},"Go",[83,407,408],{"class":93}," is",[83,410,411],{"class":93}," a",[83,413,414],{"class":93}," tool",[83,416,417],{"class":93}," for",[83,419,420],{"class":93}," managing",[83,422,423],{"class":93}," Go",[83,425,426],{"class":93}," source",[83,428,429],{"class":93}," code.\n",[83,431,432],{"class":85,"line":278},[83,433,275],{"emptyLinePlaceholder":274},[83,435,436],{"class":85,"line":284},[83,437,438],{"class":89},"Usage:\n",[83,440,441],{"class":85,"line":289},[83,442,275],{"emptyLinePlaceholder":274},[83,444,445,448,451,454,457,460],{"class":85,"line":295},[83,446,447],{"class":89},"    go",[83,449,450],{"class":154}," \u003C",[83,452,453],{"class":93},"comman",[83,455,456],{"class":147},"d",[83,458,459],{"class":154},">",[83,461,462],{"class":147}," [arguments]\n",[83,464,465],{"class":85,"line":301},[83,466,275],{"emptyLinePlaceholder":274},[83,468,470,473,476],{"class":85,"line":469},8,[83,471,472],{"class":89},"The",[83,474,475],{"class":93}," commands",[83,477,478],{"class":93}," are:\n",[83,480,482],{"class":85,"line":481},9,[83,483,275],{"emptyLinePlaceholder":274},[83,485,487,490,493,495,498],{"class":85,"line":486},10,[83,488,489],{"class":89},"    bug",[83,491,492],{"class":93},"         start",[83,494,411],{"class":93},[83,496,497],{"class":93}," bug",[83,499,500],{"class":93}," report\n",[83,502,504,507,510,513,516],{"class":85,"line":503},11,[83,505,506],{"class":89},"    build",[83,508,509],{"class":93},"       compile",[83,511,512],{"class":93}," packages",[83,514,515],{"class":93}," and",[83,517,518],{"class":93}," dependencies\n",[83,520,522,525,528,531,534,536,539],{"class":85,"line":521},12,[83,523,524],{"class":89},"    clean",[83,526,527],{"class":93},"       remove",[83,529,530],{"class":93}," object",[83,532,533],{"class":93}," files",[83,535,515],{"class":93},[83,537,538],{"class":93}," cached",[83,540,541],{"class":93}," files\n",[83,543,545,548,551,554,556,559,562],{"class":85,"line":544},13,[83,546,547],{"class":89},"    doc",[83,549,550],{"class":93},"         show",[83,552,553],{"class":93}," documentation",[83,555,417],{"class":93},[83,557,558],{"class":93}," package",[83,560,561],{"class":93}," or",[83,563,564],{"class":93}," symbol\n",[83,566,568,571,574,576,579],{"class":85,"line":567},14,[83,569,570],{"class":89},"    env",[83,572,573],{"class":93},"         print",[83,575,423],{"class":93},[83,577,578],{"class":93}," environment",[83,580,581],{"class":93}," information\n",[83,583,585,588,591,593,596,599,602],{"class":85,"line":584},15,[83,586,587],{"class":89},"    fix",[83,589,590],{"class":93},"         update",[83,592,512],{"class":93},[83,594,595],{"class":93}," to",[83,597,598],{"class":93}," use",[83,600,601],{"class":93}," new",[83,603,604],{"class":93}," APIs\n",[83,606,608,611,614],{"class":85,"line":607},16,[83,609,610],{"class":89},"    fmt",[83,612,613],{"class":93},"         gofmt",[83,615,616],{"class":147}," (reformat) package sources\n",[83,618,620,623,625,627,629,632,635],{"class":85,"line":619},17,[83,621,622],{"class":89},"    generate",[83,624,622],{"class":93},[83,626,423],{"class":93},[83,628,533],{"class":93},[83,630,631],{"class":93}," by",[83,633,634],{"class":93}," processing",[83,636,637],{"class":93}," source\n",[83,639,641,644,647,650,652,655,658,660,663],{"class":85,"line":640},18,[83,642,643],{"class":89},"    get",[83,645,646],{"class":93},"         add",[83,648,649],{"class":93}," dependencies",[83,651,595],{"class":93},[83,653,654],{"class":93}," current",[83,656,657],{"class":93}," module",[83,659,515],{"class":93},[83,661,662],{"class":93}," install",[83,664,665],{"class":93}," them\n",[83,667,669,672,675,677,679,681,683],{"class":85,"line":668},19,[83,670,671],{"class":89},"    install",[83,673,674],{"class":93},"     compile",[83,676,515],{"class":93},[83,678,662],{"class":93},[83,680,512],{"class":93},[83,682,515],{"class":93},[83,684,518],{"class":93},[83,686,688,691,694,696,698],{"class":85,"line":687},20,[83,689,690],{"class":89},"    list",[83,692,693],{"class":93},"        list",[83,695,512],{"class":93},[83,697,561],{"class":93},[83,699,700],{"class":93}," modules\n",[83,702,704,707,710],{"class":85,"line":703},21,[83,705,706],{"class":89},"    mod",[83,708,709],{"class":93},"         module",[83,711,712],{"class":93}," maintenance\n",[83,714,716,719,722],{"class":85,"line":715},22,[83,717,718],{"class":89},"    work",[83,720,721],{"class":93},"        workspace",[83,723,712],{"class":93},[83,725,727,730,733,735,737,739],{"class":85,"line":726},23,[83,728,729],{"class":89},"    run",[83,731,732],{"class":93},"         compile",[83,734,515],{"class":93},[83,736,354],{"class":93},[83,738,423],{"class":93},[83,740,741],{"class":93}," program\n",[83,743,745,748,751,754,757,759],{"class":85,"line":744},24,[83,746,747],{"class":89},"    telemetry",[83,749,750],{"class":93},"   manage",[83,752,753],{"class":93}," telemetry",[83,755,756],{"class":93}," data",[83,758,515],{"class":93},[83,760,761],{"class":93}," settings\n",[83,763,765,768,771],{"class":85,"line":764},25,[83,766,767],{"class":97},"    test",[83,769,770],{"class":93},"        test",[83,772,773],{"class":93}," packages\n",[83,775,777,780,783,786,788],{"class":85,"line":776},26,[83,778,779],{"class":89},"    tool",[83,781,782],{"class":93},"        run",[83,784,785],{"class":93}," specified",[83,787,397],{"class":93},[83,789,790],{"class":93}," tool\n",[83,792,794,797,800,802],{"class":85,"line":793},27,[83,795,796],{"class":89},"    version",[83,798,799],{"class":93},"     print",[83,801,423],{"class":93},[83,803,182],{"class":93},[83,805,807,810,813,816,819,822],{"class":85,"line":806},28,[83,808,809],{"class":89},"    vet",[83,811,812],{"class":93},"         report",[83,814,815],{"class":93}," likely",[83,817,818],{"class":93}," mistakes",[83,820,821],{"class":93}," in",[83,823,773],{"class":93},[83,825,827],{"class":85,"line":826},29,[83,828,275],{"emptyLinePlaceholder":274},[83,830,832,835,838,840,843,846,849,851],{"class":85,"line":831},30,[83,833,834],{"class":89},"Use",[83,836,837],{"class":93}," \"go help \u003Ccommand>\"",[83,839,417],{"class":93},[83,841,842],{"class":93}," more",[83,844,845],{"class":93}," information",[83,847,848],{"class":93}," about",[83,850,411],{"class":93},[83,852,853],{"class":93}," command.\n",[52,855,857],{"id":856},"packages-and-imports","Packages and Imports",[10,859,860,861,864,865,868],{},"Go does not support Classes like in OOPs programming languages such as Java, it uses the package system instead. Each package is a directory in your workspace, and each go file must belong to some package. Hence, each file should start with the keyword ",[80,862,863],{},"package"," followed by the package name. A go executable must contain ",[80,866,867],{},"package main",".",[10,870,871,872,875],{},"A package can be imported by using the ",[80,873,874],{},"import"," keyword followed by the list of packages inside parenthesis.",[10,877,878],{},"The standard library comes preinstalled, with Go, and contains the most essential and useful packages. \"fmt\" is used to export Println which prints to console.",[46,880,881],{},[10,882,883],{},"Go does not allow unused imports.",[73,885,887],{"className":261,"code":886,"language":179,"meta":78,"style":78},"package main\n\nimport (\n    \"fmt\"\n    \"log\"\n    \"time\"\n)\n",[80,888,889,893,897,902,907,912,917],{"__ignoreMap":78},[83,890,891],{"class":85,"line":86},[83,892,269],{},[83,894,895],{"class":85,"line":161},[83,896,275],{"emptyLinePlaceholder":274},[83,898,899],{"class":85,"line":278},[83,900,901],{},"import (\n",[83,903,904],{"class":85,"line":284},[83,905,906],{},"    \"fmt\"\n",[83,908,909],{"class":85,"line":289},[83,910,911],{},"    \"log\"\n",[83,913,914],{"class":85,"line":295},[83,915,916],{},"    \"time\"\n",[83,918,919],{"class":85,"line":301},[83,920,921],{},")\n",[52,923,925],{"id":924},"using-an-external-package","Using an external package",[10,927,928],{},"When we need our code to do something that might have been implemented by someone else, we can look for a package that has functions we can use in our code.",[10,930,931],{},"Let's Make our printed message a little more interesting with a function from an external module.",[57,933,934,943,946,949],{},[27,935,936,937,942],{},"Visit ",[62,938,941],{"href":939,"rel":940},"https:\u002F\u002Fpkg.go.dev",[66],"pkg.go.dev"," and search for a \"quote\" package.",[27,944,945],{},"Locate and click the rsc.io\u002Fquote package in search results (if we see rsc.io\u002Fquote\u002Fv4, ignore it for now).",[27,947,948],{},"In the Documentation section, under Index, note the list of functions we can call from our code. we'll use the Go function.",[27,950,951],{},"At the top of this page, note that package quote is included in the rsc.io\u002Fquote module.",[10,953,954,955,958],{},"we can use the pkg.go.dev site to find published modules whose packages have functions we can use in our own code. Packages are published in modules like ",[80,956,957],{},"rsc.io\u002Fquote"," where others can use them. Modules are improved with new versions over time, and we can upgrade our code to use the improved versions.",[57,960,961,1014,1039],{"start":289},[27,962,254,963,966,967],{},[80,964,965],{},"quote.go"," and add the following code",[73,968,970],{"className":261,"code":969,"language":179,"meta":78,"style":78},"package main\n\nimport (\n    \"fmt\"\n    \"rsc.io\u002Fquote\"\n)\n\nfunc main() {\n    fmt.Println(quote.Go())\n}\n",[80,971,972,976,980,984,988,993,997,1001,1005,1010],{"__ignoreMap":78},[83,973,974],{"class":85,"line":86},[83,975,269],{},[83,977,978],{"class":85,"line":161},[83,979,275],{"emptyLinePlaceholder":274},[83,981,982],{"class":85,"line":278},[83,983,901],{},[83,985,986],{"class":85,"line":284},[83,987,906],{},[83,989,990],{"class":85,"line":289},[83,991,992],{},"    \"rsc.io\u002Fquote\"\n",[83,994,995],{"class":85,"line":295},[83,996,921],{},[83,998,999],{"class":85,"line":301},[83,1000,275],{"emptyLinePlaceholder":274},[83,1002,1003],{"class":85,"line":469},[83,1004,292],{},[83,1006,1007],{"class":85,"line":481},[83,1008,1009],{},"    fmt.Println(quote.Go())\n",[83,1011,1012],{"class":85,"line":486},[83,1013,304],{},[27,1015,1016,1017,1020,1021,1024,1025],{},"Add new module requirements and sums.",[1018,1019],"br",{},"Go will add the quote module as a requirement, as well as a ",[80,1022,1023],{},"go.sum"," file for use in authenticating the module.",[73,1026,1028],{"className":75,"code":1027,"language":77,"meta":78,"style":78},"go mod tidy\n",[80,1029,1030],{"__ignoreMap":78},[83,1031,1032,1034,1036],{"class":85,"line":86},[83,1033,179],{"class":89},[83,1035,245],{"class":93},[83,1037,1038],{"class":93}," tidy\n",[27,1040,1041,1042,1056,1058,1059,1072,1074],{},"Run the code to see the message generated by the function we're calling.",[73,1043,1045],{"className":75,"code":1044,"language":77,"meta":78,"style":78},"go run quote.go\n",[80,1046,1047],{"__ignoreMap":78},[83,1048,1049,1051,1053],{"class":85,"line":86},[83,1050,179],{"class":89},[83,1052,354],{"class":93},[83,1054,1055],{"class":93}," quote.go\n",[1018,1057],{},"Output:",[73,1060,1062],{"className":75,"code":1061,"language":77,"meta":78,"style":78},"Don't communicate by sharing memory, share memory by communicating.\n",[80,1063,1064],{"__ignoreMap":78},[83,1065,1066,1069],{"class":85,"line":86},[83,1067,1068],{"class":89},"Don",[83,1070,1071],{"class":89},"'t communicate by sharing memory, share memory by communicating.\n",[1018,1073],{},"Notice that our code calls the Go function, printing a clever message about communication.",[46,1076,1077],{},[10,1078,1079,1080,1083,1084,1086],{},"When we ran ",[80,1081,1082],{},"go mod tidy",", it located and downloaded the ",[80,1085,957],{}," module that contains the package you imported. By default, it downloaded the latest version.",[52,1088,1090],{"id":1089},"language-concepts","Language concepts",[1092,1093,1095],"h3",{"id":1094},"_1-variables","1. Variables",[10,1097,1098,1099,1102],{},"Go’s basic primitive types are bool, string, int, uint, float, and complex, the size of the type can be specified next to the type, uint32. A variable is declared by the ",[80,1100,1101],{},"var"," keyword followed by the variable name and the type.",[10,1104,1105,1106,1109],{},"variables can also be initialized with a shorthand notation ",[80,1107,1108],{},":="," as Go can infer the type.",[46,1111,1112],{},[10,1113,1114],{},"Just like imports, unused variables are not allowed.",[73,1116,1118],{"className":261,"code":1117,"language":179,"meta":78,"style":78},"package main\n\nvar x int = 5\nvar y int = 6\n\nsum := x + y\n",[80,1119,1120,1124,1128,1133,1138,1142],{"__ignoreMap":78},[83,1121,1122],{"class":85,"line":86},[83,1123,269],{},[83,1125,1126],{"class":85,"line":161},[83,1127,275],{"emptyLinePlaceholder":274},[83,1129,1130],{"class":85,"line":278},[83,1131,1132],{},"var x int = 5\n",[83,1134,1135],{"class":85,"line":284},[83,1136,1137],{},"var y int = 6\n",[83,1139,1140],{"class":85,"line":289},[83,1141,275],{"emptyLinePlaceholder":274},[83,1143,1144],{"class":85,"line":295},[83,1145,1146],{},"sum := x + y\n",[10,1148,1149],{},"Also, Go does not use semicolons to end a statement.",[10,1151,1152],{},"An important point to note is how Go scopes variables with a package, a variable is public if the first letter is in Captial, else private, same goes for functions.",[73,1154,1156],{"className":261,"code":1155,"language":179,"meta":78,"style":78},"package main\n\nX := 5 \u002F\u002F public\ny := 6 \u002F\u002F private\n\nfunc Add() { \u002F\u002F public\n\n}\n\nfunc add() { \u002F\u002F private\n\n}\n",[80,1157,1158,1162,1166,1171,1176,1180,1185,1189,1193,1197,1202,1206],{"__ignoreMap":78},[83,1159,1160],{"class":85,"line":86},[83,1161,269],{},[83,1163,1164],{"class":85,"line":161},[83,1165,275],{"emptyLinePlaceholder":274},[83,1167,1168],{"class":85,"line":278},[83,1169,1170],{},"X := 5 \u002F\u002F public\n",[83,1172,1173],{"class":85,"line":284},[83,1174,1175],{},"y := 6 \u002F\u002F private\n",[83,1177,1178],{"class":85,"line":289},[83,1179,275],{"emptyLinePlaceholder":274},[83,1181,1182],{"class":85,"line":295},[83,1183,1184],{},"func Add() { \u002F\u002F public\n",[83,1186,1187],{"class":85,"line":301},[83,1188,275],{"emptyLinePlaceholder":274},[83,1190,1191],{"class":85,"line":469},[83,1192,304],{},[83,1194,1195],{"class":85,"line":481},[83,1196,275],{"emptyLinePlaceholder":274},[83,1198,1199],{"class":85,"line":486},[83,1200,1201],{},"func add() { \u002F\u002F private\n",[83,1203,1204],{"class":85,"line":503},[83,1205,275],{"emptyLinePlaceholder":274},[83,1207,1208],{"class":85,"line":521},[83,1209,304],{},[1092,1211,1213],{"id":1212},"_2-functions","2. Functions",[10,1215,1216,1217,1220,1221,1223],{},"Functions are an essential part of Go, and of course, the above won’t work as execution has to happen in a function body. Functions are declared with the keyword ",[80,1218,1219],{},"func"," followed by the function name, arguments, and return type. A Go application must contain the ",[80,1222,313],{}," function which is the entry point to the application. It does not take any arguments or return anything. The opening braces of the function must start at the same level as the function and cannot move to the new line.",[10,1225,1226],{},"function parameters are declared with their name followed by the type and separated by a comma. The return type must be provided if the function returns, as a shortcut the return variable can also be declared to avoid declaring another variable inside the function, here’s an example.",[73,1228,1230],{"className":261,"code":1229,"language":179,"meta":78,"style":78},"package main\n\nfunc sum(x int, y int) int {\n    sum := x + y\n    return sum\n}\n\n\u002F\u002F OR\n\nfunc sum(x int, y int) (sum int) {\n    sum := x + y\n    return\n}\n",[80,1231,1232,1236,1240,1245,1250,1255,1259,1263,1268,1272,1277,1281,1286],{"__ignoreMap":78},[83,1233,1234],{"class":85,"line":86},[83,1235,269],{},[83,1237,1238],{"class":85,"line":161},[83,1239,275],{"emptyLinePlaceholder":274},[83,1241,1242],{"class":85,"line":278},[83,1243,1244],{},"func sum(x int, y int) int {\n",[83,1246,1247],{"class":85,"line":284},[83,1248,1249],{},"    sum := x + y\n",[83,1251,1252],{"class":85,"line":289},[83,1253,1254],{},"    return sum\n",[83,1256,1257],{"class":85,"line":295},[83,1258,304],{},[83,1260,1261],{"class":85,"line":301},[83,1262,275],{"emptyLinePlaceholder":274},[83,1264,1265],{"class":85,"line":469},[83,1266,1267],{},"\u002F\u002F OR\n",[83,1269,1270],{"class":85,"line":481},[83,1271,275],{"emptyLinePlaceholder":274},[83,1273,1274],{"class":85,"line":486},[83,1275,1276],{},"func sum(x int, y int) (sum int) {\n",[83,1278,1279],{"class":85,"line":503},[83,1280,1249],{},[83,1282,1283],{"class":85,"line":521},[83,1284,1285],{},"    return\n",[83,1287,1288],{"class":85,"line":544},[83,1289,304],{},[1092,1291,1293],{"id":1292},"_3-arrays-slices-and-maps","3. Arrays, Slices, and Maps",[10,1295,1296],{},"Arrays can be declared by simply specifying the datatype next to brackets with an integer denoting the size of the array. Then, arrays can be assigned by their index, a more convenient way to initialize is to use the shorthand syntax along with the data in parenthesis.",[73,1298,1300],{"className":261,"code":1299,"language":179,"meta":78,"style":78},"package main\n\nvar arr [4]int\narr[0] = 1\narr[1] = 2\n\n\u002F\u002F OR\n\narr := [4]int{1,2,3,4}\n",[80,1301,1302,1306,1310,1315,1320,1325,1329,1333,1337],{"__ignoreMap":78},[83,1303,1304],{"class":85,"line":86},[83,1305,269],{},[83,1307,1308],{"class":85,"line":161},[83,1309,275],{"emptyLinePlaceholder":274},[83,1311,1312],{"class":85,"line":278},[83,1313,1314],{},"var arr [4]int\n",[83,1316,1317],{"class":85,"line":284},[83,1318,1319],{},"arr[0] = 1\n",[83,1321,1322],{"class":85,"line":289},[83,1323,1324],{},"arr[1] = 2\n",[83,1326,1327],{"class":85,"line":295},[83,1328,275],{"emptyLinePlaceholder":274},[83,1330,1331],{"class":85,"line":301},[83,1332,1267],{},[83,1334,1335],{"class":85,"line":469},[83,1336,275],{"emptyLinePlaceholder":274},[83,1338,1339],{"class":85,"line":481},[83,1340,1341],{},"arr := [4]int{1,2,3,4}\n",[10,1343,1344,1345,1348],{},"But there’s a problem here. You cannot modify the length of the array, wouldn't it be more convenient when you don’t know the size yet? That’s where ",[80,1346,1347],{},"Slices"," come in, slices are simply dynamic arrays. you can declare a slice just like arrays, without specifying the size.",[10,1350,1351],{},"Slices can be really useful in performing a lot of operations. The copy or append function can be used to manipulate the slice. Slices can also be concatenated using the append with the spread operator(…). A slice can be sliced using its indices within the brackets. Below are some examples.",[73,1353,1355],{"className":261,"code":1354,"language":179,"meta":78,"style":78},"package main\n\nimport \"fmt\"\n\nfunc main() {\n    slice := []int{1,2,3,4,5}\n\n    slice1 := slice[2:]\n    slice2 := slice[:2]\n\n    slice = append(slice ,4)\n\n    slicecat := append(slice, slice...)\n\n    fmt.Println(slice, slice1, slice2, slicecat)\n}\n",[80,1356,1357,1361,1365,1369,1373,1377,1382,1386,1391,1396,1400,1405,1409,1414,1418,1423],{"__ignoreMap":78},[83,1358,1359],{"class":85,"line":86},[83,1360,269],{},[83,1362,1363],{"class":85,"line":161},[83,1364,275],{"emptyLinePlaceholder":274},[83,1366,1367],{"class":85,"line":278},[83,1368,281],{},[83,1370,1371],{"class":85,"line":284},[83,1372,275],{"emptyLinePlaceholder":274},[83,1374,1375],{"class":85,"line":289},[83,1376,292],{},[83,1378,1379],{"class":85,"line":295},[83,1380,1381],{},"    slice := []int{1,2,3,4,5}\n",[83,1383,1384],{"class":85,"line":301},[83,1385,275],{"emptyLinePlaceholder":274},[83,1387,1388],{"class":85,"line":469},[83,1389,1390],{},"    slice1 := slice[2:]\n",[83,1392,1393],{"class":85,"line":481},[83,1394,1395],{},"    slice2 := slice[:2]\n",[83,1397,1398],{"class":85,"line":486},[83,1399,275],{"emptyLinePlaceholder":274},[83,1401,1402],{"class":85,"line":503},[83,1403,1404],{},"    slice = append(slice ,4)\n",[83,1406,1407],{"class":85,"line":521},[83,1408,275],{"emptyLinePlaceholder":274},[83,1410,1411],{"class":85,"line":544},[83,1412,1413],{},"    slicecat := append(slice, slice...)\n",[83,1415,1416],{"class":85,"line":567},[83,1417,275],{"emptyLinePlaceholder":274},[83,1419,1420],{"class":85,"line":584},[83,1421,1422],{},"    fmt.Println(slice, slice1, slice2, slicecat)\n",[83,1424,1425],{"class":85,"line":607},[83,1426,304],{},[10,1428,1429],{},"The append function does not modify the slice but returns a new slice from the given one. Here’s the output.",[73,1431,1433],{"className":75,"code":1432,"language":77,"meta":78,"style":78},"# output\n[1 2 3 4 5 4] [3 4 5] [1 2] [1 2 3 4 5 4 1 2 3 4 5 4]\n",[80,1434,1435,1441],{"__ignoreMap":78},[83,1436,1437],{"class":85,"line":86},[83,1438,1440],{"class":1439},"sAwPA","# output\n",[83,1442,1443,1446,1449,1452,1455,1458,1461,1464,1467,1469,1472,1474,1477,1479,1481,1483,1485,1487,1489,1492,1494,1496,1498,1500],{"class":85,"line":161},[83,1444,1445],{"class":147},"[",[83,1447,1448],{"class":97},"1",[83,1450,1451],{"class":97}," 2",[83,1453,1454],{"class":97}," 3",[83,1456,1457],{"class":97}," 4",[83,1459,1460],{"class":97}," 5",[83,1462,1463],{"class":147}," 4] [",[83,1465,1466],{"class":97},"3",[83,1468,1457],{"class":97},[83,1470,1471],{"class":147}," 5] [",[83,1473,1448],{"class":97},[83,1475,1476],{"class":147}," 2] [",[83,1478,1448],{"class":97},[83,1480,1451],{"class":97},[83,1482,1454],{"class":97},[83,1484,1457],{"class":97},[83,1486,1460],{"class":97},[83,1488,1457],{"class":97},[83,1490,1491],{"class":97}," 1",[83,1493,1451],{"class":97},[83,1495,1454],{"class":97},[83,1497,1457],{"class":97},[83,1499,1460],{"class":97},[83,1501,1502],{"class":147}," 4]\n",[10,1504,1505],{},"Maps are equivalent to a HasMap in Java or a Dictionary in python. They store key-value pairs. A map can be created using the make keyword followed by the keyword map and the datatype of the key in brackets and value next to it.",[10,1507,1508,1509,1512],{},"Maps are simple to operate on, they can be assigned values by using the ",[80,1510,1511],{},"[ ]"," operator specifying the key and value, and a key can be removed by using the delete function.",[73,1514,1516],{"className":261,"code":1515,"language":179,"meta":78,"style":78},"package main\n\nimport \"fmt\"\n\nfunc main() {\n    elements := make(map[string]int)\n\n    elements[\"first\"] = 1\n    elements[\"second\"] = 2\n\n    fmt.Println(elements)\n\n    delete(elements, \"first\")\n\n    fmt.Println(elements)\n}\n",[80,1517,1518,1522,1526,1530,1534,1538,1543,1547,1552,1557,1561,1566,1570,1575,1579,1583],{"__ignoreMap":78},[83,1519,1520],{"class":85,"line":86},[83,1521,269],{},[83,1523,1524],{"class":85,"line":161},[83,1525,275],{"emptyLinePlaceholder":274},[83,1527,1528],{"class":85,"line":278},[83,1529,281],{},[83,1531,1532],{"class":85,"line":284},[83,1533,275],{"emptyLinePlaceholder":274},[83,1535,1536],{"class":85,"line":289},[83,1537,292],{},[83,1539,1540],{"class":85,"line":295},[83,1541,1542],{},"    elements := make(map[string]int)\n",[83,1544,1545],{"class":85,"line":301},[83,1546,275],{"emptyLinePlaceholder":274},[83,1548,1549],{"class":85,"line":469},[83,1550,1551],{},"    elements[\"first\"] = 1\n",[83,1553,1554],{"class":85,"line":481},[83,1555,1556],{},"    elements[\"second\"] = 2\n",[83,1558,1559],{"class":85,"line":486},[83,1560,275],{"emptyLinePlaceholder":274},[83,1562,1563],{"class":85,"line":503},[83,1564,1565],{},"    fmt.Println(elements)\n",[83,1567,1568],{"class":85,"line":521},[83,1569,275],{"emptyLinePlaceholder":274},[83,1571,1572],{"class":85,"line":544},[83,1573,1574],{},"    delete(elements, \"first\")\n",[83,1576,1577],{"class":85,"line":567},[83,1578,275],{"emptyLinePlaceholder":274},[83,1580,1581],{"class":85,"line":584},[83,1582,1565],{},[83,1584,1585],{"class":85,"line":607},[83,1586,304],{},[10,1588,1058],{},[73,1590,1592],{"className":75,"code":1591,"language":77,"meta":78,"style":78},"map[first:1 second:2]\nmap[second:2]\n",[80,1593,1594,1602],{"__ignoreMap":78},[83,1595,1596,1599],{"class":85,"line":86},[83,1597,1598],{"class":89},"map[first:1",[83,1600,1601],{"class":93}," second:2]\n",[83,1603,1604],{"class":85,"line":161},[83,1605,1606],{"class":89},"map[second:2]\n",[1092,1608,1610],{"id":1609},"_3-loops","3. Loops",[10,1612,1613,1614,1617,1618,1620],{},"Loops in Go exist in the simplest form, there is only one looping syntax, the ",[80,1615,1616],{},"for"," loop. The ",[80,1619,1616],{}," loop can be written in multiple ways to meet your looping needs. The first syntax is a familiar one starting with the pointer variable i and followed by condition and incrementation. The below example will print 1 to 5.",[73,1622,1624],{"className":261,"code":1623,"language":179,"meta":78,"style":78},"package main\n\nimport \"fmt\"\n\nfunc main() {\n    arr := []int{1,2,3,4,5}\n\n    for i := 0; i \u003C len(arr); i++ {\n        fmt.Println(arr[i])\n    }\n}\n",[80,1625,1626,1630,1634,1638,1642,1646,1651,1655,1660,1665,1670],{"__ignoreMap":78},[83,1627,1628],{"class":85,"line":86},[83,1629,269],{},[83,1631,1632],{"class":85,"line":161},[83,1633,275],{"emptyLinePlaceholder":274},[83,1635,1636],{"class":85,"line":278},[83,1637,281],{},[83,1639,1640],{"class":85,"line":284},[83,1641,275],{"emptyLinePlaceholder":274},[83,1643,1644],{"class":85,"line":289},[83,1645,292],{},[83,1647,1648],{"class":85,"line":295},[83,1649,1650],{},"    arr := []int{1,2,3,4,5}\n",[83,1652,1653],{"class":85,"line":301},[83,1654,275],{"emptyLinePlaceholder":274},[83,1656,1657],{"class":85,"line":469},[83,1658,1659],{},"    for i := 0; i \u003C len(arr); i++ {\n",[83,1661,1662],{"class":85,"line":481},[83,1663,1664],{},"        fmt.Println(arr[i])\n",[83,1666,1667],{"class":85,"line":486},[83,1668,1669],{},"    }\n",[83,1671,1672],{"class":85,"line":503},[83,1673,304],{},[10,1675,1676],{},"Oh! you badly miss the while loop? Don’t worry, Go has you covered, all you have to do is mention the condition with the for loop and use a pointer declared outside the loop just how you would when using a while loop.",[73,1678,1680],{"className":261,"code":1679,"language":179,"meta":78,"style":78},"package main\n\nimport \"fmt\"\n\nfunc main() {\n    arr := []int{1,2,3,4,5}\n\n    i := 0\n    for i \u003C len(arr) {\n        fmt.Println(arr[i])\n        i++\n    }\n}\n",[80,1681,1682,1686,1690,1694,1698,1702,1706,1710,1715,1720,1724,1729,1733],{"__ignoreMap":78},[83,1683,1684],{"class":85,"line":86},[83,1685,269],{},[83,1687,1688],{"class":85,"line":161},[83,1689,275],{"emptyLinePlaceholder":274},[83,1691,1692],{"class":85,"line":278},[83,1693,281],{},[83,1695,1696],{"class":85,"line":284},[83,1697,275],{"emptyLinePlaceholder":274},[83,1699,1700],{"class":85,"line":289},[83,1701,292],{},[83,1703,1704],{"class":85,"line":295},[83,1705,1650],{},[83,1707,1708],{"class":85,"line":301},[83,1709,275],{"emptyLinePlaceholder":274},[83,1711,1712],{"class":85,"line":469},[83,1713,1714],{},"    i := 0\n",[83,1716,1717],{"class":85,"line":481},[83,1718,1719],{},"    for i \u003C len(arr) {\n",[83,1721,1722],{"class":85,"line":486},[83,1723,1664],{},[83,1725,1726],{"class":85,"line":503},[83,1727,1728],{},"        i++\n",[83,1730,1731],{"class":85,"line":521},[83,1732,1669],{},[83,1734,1735],{"class":85,"line":544},[83,1736,304],{},[10,1738,1739],{},"The range function provides an easy way to access the index as well as value.",[73,1741,1743],{"className":261,"code":1742,"language":179,"meta":78,"style":78},"package main\n\nimport \"fmt\"\n\nfunc main() {\n    arr := []int{1,2,3,4,5}\n\n    for i,v := range(arr) {\n        fmt.Println(i, v)\n    }\n}\n",[80,1744,1745,1749,1753,1757,1761,1765,1769,1773,1778,1783,1787],{"__ignoreMap":78},[83,1746,1747],{"class":85,"line":86},[83,1748,269],{},[83,1750,1751],{"class":85,"line":161},[83,1752,275],{"emptyLinePlaceholder":274},[83,1754,1755],{"class":85,"line":278},[83,1756,281],{},[83,1758,1759],{"class":85,"line":284},[83,1760,275],{"emptyLinePlaceholder":274},[83,1762,1763],{"class":85,"line":289},[83,1764,292],{},[83,1766,1767],{"class":85,"line":295},[83,1768,1650],{},[83,1770,1771],{"class":85,"line":301},[83,1772,275],{"emptyLinePlaceholder":274},[83,1774,1775],{"class":85,"line":469},[83,1776,1777],{},"    for i,v := range(arr) {\n",[83,1779,1780],{"class":85,"line":481},[83,1781,1782],{},"        fmt.Println(i, v)\n",[83,1784,1785],{"class":85,"line":486},[83,1786,1669],{},[83,1788,1789],{"class":85,"line":503},[83,1790,304],{},[1092,1792,1794],{"id":1793},"_4-struct","4. Struct",[10,1796,376,1797,1800,1801,1804,1805,1807],{},[80,1798,1799],{},"struct"," keyword is to define a shape to your data. Since Go does not support classes, data of a certain shape requirement can be stored in variables of that type of struct. A struct is created using the keyword ",[80,1802,1803],{},"type"," and its properties can be accessed by the ",[80,1806,868],{}," operator.",[73,1809,1811],{"className":261,"code":1810,"language":179,"meta":78,"style":78},"package main\n\nimport \"fmt\"\n\nfunc main() {\n    type Animal struct {\n        Name        string\n        animalType  string\n    }\n\n    giraffe := Animal(\"Giraffe\", \"Mammal\")\n\n    fmt.Println(giraffe.Name, giraffe.animalType)\n}\n",[80,1812,1813,1817,1821,1825,1829,1833,1838,1843,1848,1852,1856,1861,1865,1870],{"__ignoreMap":78},[83,1814,1815],{"class":85,"line":86},[83,1816,269],{},[83,1818,1819],{"class":85,"line":161},[83,1820,275],{"emptyLinePlaceholder":274},[83,1822,1823],{"class":85,"line":278},[83,1824,281],{},[83,1826,1827],{"class":85,"line":284},[83,1828,275],{"emptyLinePlaceholder":274},[83,1830,1831],{"class":85,"line":289},[83,1832,292],{},[83,1834,1835],{"class":85,"line":295},[83,1836,1837],{},"    type Animal struct {\n",[83,1839,1840],{"class":85,"line":301},[83,1841,1842],{},"        Name        string\n",[83,1844,1845],{"class":85,"line":469},[83,1846,1847],{},"        animalType  string\n",[83,1849,1850],{"class":85,"line":481},[83,1851,1669],{},[83,1853,1854],{"class":85,"line":486},[83,1855,275],{"emptyLinePlaceholder":274},[83,1857,1858],{"class":85,"line":503},[83,1859,1860],{},"    giraffe := Animal(\"Giraffe\", \"Mammal\")\n",[83,1862,1863],{"class":85,"line":521},[83,1864,275],{"emptyLinePlaceholder":274},[83,1866,1867],{"class":85,"line":544},[83,1868,1869],{},"    fmt.Println(giraffe.Name, giraffe.animalType)\n",[83,1871,1872],{"class":85,"line":567},[83,1873,304],{},[1092,1875,1877],{"id":1876},"_5-nil-error-and-multiple-return-values","5. nil, error, and multiple return values",[10,1879,1880],{},"Go provides some smooth ways to handle the error and nil values. Both error and nil are native built-in types that can be used to perform validation before performing some operation. Go also supports returning multiple types from a function, this can be done using specifying the type within parenthesis in place of the return type.",[73,1882,1884],{"className":261,"code":1883,"language":179,"meta":78,"style":78},"package main\n\nimport \"fmt\"\n\nfunc main() {\n    a,b := sum(5,10)\n}\n\nfunc sum(x int, y int) (sum int, diff int) {\n    sum = x + y\n    diff = x - y\n    return\n}\n",[80,1885,1886,1890,1894,1898,1902,1906,1911,1915,1919,1924,1929,1934,1938],{"__ignoreMap":78},[83,1887,1888],{"class":85,"line":86},[83,1889,269],{},[83,1891,1892],{"class":85,"line":161},[83,1893,275],{"emptyLinePlaceholder":274},[83,1895,1896],{"class":85,"line":278},[83,1897,281],{},[83,1899,1900],{"class":85,"line":284},[83,1901,275],{"emptyLinePlaceholder":274},[83,1903,1904],{"class":85,"line":289},[83,1905,292],{},[83,1907,1908],{"class":85,"line":295},[83,1909,1910],{},"    a,b := sum(5,10)\n",[83,1912,1913],{"class":85,"line":301},[83,1914,304],{},[83,1916,1917],{"class":85,"line":469},[83,1918,275],{"emptyLinePlaceholder":274},[83,1920,1921],{"class":85,"line":481},[83,1922,1923],{},"func sum(x int, y int) (sum int, diff int) {\n",[83,1925,1926],{"class":85,"line":486},[83,1927,1928],{},"    sum = x + y\n",[83,1930,1931],{"class":85,"line":503},[83,1932,1933],{},"    diff = x - y\n",[83,1935,1936],{"class":85,"line":521},[83,1937,1285],{},[83,1939,1940],{"class":85,"line":544},[83,1941,304],{},[10,1943,1944],{},"errors or nil can be returned depending on the operation performed using an if check. Here’s an example showing how you can handle errors by checking the input for a square root function.",[73,1946,1948],{"className":261,"code":1947,"language":179,"meta":78,"style":78},"package main\n\nimport (\n    \"fmt\"\n    \"math\"\n    \"errors\"\n)\n\nfunc main() {\n    result, err := sqrt(25)\n\n    if err != nil {\n        fmt.Println(err)\n    } else {\n        fmt.Println(result)\n    }\n}\n\nfunc sqrt(x float64) (float64, error) {\n    if x \u003C 0 {\n        return 0 , errors.New(\"x must be non negative number\")\n    }\n\n    retun math.Sqrt(x), nil\n}\n",[80,1949,1950,1954,1958,1962,1966,1971,1976,1980,1984,1988,1993,1997,2002,2007,2012,2017,2021,2025,2029,2034,2039,2044,2048,2052,2057],{"__ignoreMap":78},[83,1951,1952],{"class":85,"line":86},[83,1953,269],{},[83,1955,1956],{"class":85,"line":161},[83,1957,275],{"emptyLinePlaceholder":274},[83,1959,1960],{"class":85,"line":278},[83,1961,901],{},[83,1963,1964],{"class":85,"line":284},[83,1965,906],{},[83,1967,1968],{"class":85,"line":289},[83,1969,1970],{},"    \"math\"\n",[83,1972,1973],{"class":85,"line":295},[83,1974,1975],{},"    \"errors\"\n",[83,1977,1978],{"class":85,"line":301},[83,1979,921],{},[83,1981,1982],{"class":85,"line":469},[83,1983,275],{"emptyLinePlaceholder":274},[83,1985,1986],{"class":85,"line":481},[83,1987,292],{},[83,1989,1990],{"class":85,"line":486},[83,1991,1992],{},"    result, err := sqrt(25)\n",[83,1994,1995],{"class":85,"line":503},[83,1996,275],{"emptyLinePlaceholder":274},[83,1998,1999],{"class":85,"line":521},[83,2000,2001],{},"    if err != nil {\n",[83,2003,2004],{"class":85,"line":544},[83,2005,2006],{},"        fmt.Println(err)\n",[83,2008,2009],{"class":85,"line":567},[83,2010,2011],{},"    } else {\n",[83,2013,2014],{"class":85,"line":584},[83,2015,2016],{},"        fmt.Println(result)\n",[83,2018,2019],{"class":85,"line":607},[83,2020,1669],{},[83,2022,2023],{"class":85,"line":619},[83,2024,304],{},[83,2026,2027],{"class":85,"line":640},[83,2028,275],{"emptyLinePlaceholder":274},[83,2030,2031],{"class":85,"line":668},[83,2032,2033],{},"func sqrt(x float64) (float64, error) {\n",[83,2035,2036],{"class":85,"line":687},[83,2037,2038],{},"    if x \u003C 0 {\n",[83,2040,2041],{"class":85,"line":703},[83,2042,2043],{},"        return 0 , errors.New(\"x must be non negative number\")\n",[83,2045,2046],{"class":85,"line":715},[83,2047,1669],{},[83,2049,2050],{"class":85,"line":726},[83,2051,275],{"emptyLinePlaceholder":274},[83,2053,2054],{"class":85,"line":744},[83,2055,2056],{},"    retun math.Sqrt(x), nil\n",[83,2058,2059],{"class":85,"line":764},[83,2060,304],{},[1092,2062,2064],{"id":2063},"_6-pointers","6. Pointers",[10,2066,2067,2068,2071,2072,2075,2076,2078],{},"Pointers in Go are similar to pointers in other languages, you can refer to the memory address of the variable by prefixing the variable with an ",[80,2069,2070],{},"ampersand(&)"," symbol and dereference it using an ",[80,2073,2074],{},"asterisk(*)",", by default, go passes arguments by value not reference, you can accomplish this by prefixing that type of the argument in the function with an ",[80,2077,2074],{},", here’s an example.",[73,2080,2082],{"className":261,"code":2081,"language":179,"meta":78,"style":78},"package main\n\nimport \"fmt\"\n\nfunc main() {\n    i := 5\n    increment(&i)\n    fmt.Println(i)\n}\n\nfunc increment(i *int) {\n    *i++\n}\n",[80,2083,2084,2088,2092,2096,2100,2104,2109,2114,2119,2123,2127,2132,2137],{"__ignoreMap":78},[83,2085,2086],{"class":85,"line":86},[83,2087,269],{},[83,2089,2090],{"class":85,"line":161},[83,2091,275],{"emptyLinePlaceholder":274},[83,2093,2094],{"class":85,"line":278},[83,2095,281],{},[83,2097,2098],{"class":85,"line":284},[83,2099,275],{"emptyLinePlaceholder":274},[83,2101,2102],{"class":85,"line":289},[83,2103,292],{},[83,2105,2106],{"class":85,"line":295},[83,2107,2108],{},"    i := 5\n",[83,2110,2111],{"class":85,"line":301},[83,2112,2113],{},"    increment(&i)\n",[83,2115,2116],{"class":85,"line":469},[83,2117,2118],{},"    fmt.Println(i)\n",[83,2120,2121],{"class":85,"line":481},[83,2122,304],{},[83,2124,2125],{"class":85,"line":486},[83,2126,275],{"emptyLinePlaceholder":274},[83,2128,2129],{"class":85,"line":503},[83,2130,2131],{},"func increment(i *int) {\n",[83,2133,2134],{"class":85,"line":521},[83,2135,2136],{},"    *i++\n",[83,2138,2139],{"class":85,"line":544},[83,2140,304],{},[10,2142,2143,2144,2147,2148,2151],{},"without the ",[80,2145,2146],{},"&"," it’d print 5 as a copy of the variable would have been passed, and once we have the reference, we need to deference the memory to get the value by using ",[80,2149,2150],{},"*"," on the variable again.",[10,2153,2154,2155,2158],{},"That’s it! you should be now ready to write your first program in Go, try practicing the code snippets and if you feel like challenging yourself more, try writing a basic HTTP server using the ",[80,2156,2157],{},"net"," package. This should give you enough practice to write some awesome packages or contribute to your favorite Go repository.",[10,2160,2161],{},"We'll explore concurrency and other powerful features of Go in another blog—so stay tuned.",[10,2163,2164],{},"Thanks for sticking around and coding along!",[10,2166,2167],{},"Here are some additional resources if you wish to dive deeper.",[24,2169,2170,2177,2184,2191],{},[27,2171,2172],{},[62,2173,2176],{"href":2174,"rel":2175},"https:\u002F\u002Fgo.dev\u002F",[66],"go.dev",[27,2178,2179],{},[62,2180,2183],{"href":2181,"rel":2182},"https:\u002F\u002Fyoutu.be\u002FXCZWyN9ZbEQ?si=wT5Hf6TNadDtQiZk",[66],"Golang Tutorial By Nana",[27,2185,2186],{},[62,2187,2190],{"href":2188,"rel":2189},"https:\u002F\u002Fyoutube.com\u002Fplaylist?list=PL0xRBLFXXsP7-0IVCmoo2FEWBrQzfH2l8&si=7LoFNs4RBqA46C92",[66],"How To Golang Playlist by Anthony GG",[27,2192,2193],{},[62,2194,2197],{"href":2195,"rel":2196},"https:\u002F\u002Fmedium.com\u002Fa-journey-with-go",[66],"A Journey With Go",[10,2199,2200],{},"Until next time happy coding, and go Go!",[2202,2203,2204],"style",{},"html pre.shiki code .s7eDp, html code.shiki .s7eDp{--shiki-default:#6F42C1}html pre.shiki code .sYBdl, html code.shiki .sYBdl{--shiki-default:#032F62}html pre.shiki code .sYu0t, html code.shiki .sYu0t{--shiki-default:#005CC5}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 pre.shiki code .sgsFI, html code.shiki .sgsFI{--shiki-default:#24292E}html pre.shiki code .sD7c4, html code.shiki .sD7c4{--shiki-default:#D73A49}html pre.shiki code .sAwPA, html code.shiki .sAwPA{--shiki-default:#6A737D}",{"title":78,"searchDepth":161,"depth":161,"links":2206},[2207,2208,2209,2210,2211],{"id":54,"depth":161,"text":55},{"id":204,"depth":161,"text":205},{"id":856,"depth":161,"text":857},{"id":924,"depth":161,"text":925},{"id":1089,"depth":161,"text":1090,"children":2212},[2213,2214,2215,2216,2217,2218,2219],{"id":1094,"depth":278,"text":1095},{"id":1212,"depth":278,"text":1213},{"id":1292,"depth":278,"text":1293},{"id":1609,"depth":278,"text":1610},{"id":1793,"depth":278,"text":1794},{"id":1876,"depth":278,"text":1877},{"id":2063,"depth":278,"text":2064},"2025-04-25","Go was designed at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson to improve programming productivity in an era of multicore, networked machines and large codebases.",false,"md",null,{},"\u002Fblogs\u002Fgolang-getting-started",{"title":5,"description":2221},"blogs\u002Fgolang-getting-started\u002Findex",[2230,2231,179,2232,2233,2234,2235],"programming language","computer science","golang","cloud","programming","software","wI6FTyHnjv3R8FTIinA8Er38keVqLE8tFpfcR7aX8Jc",1782753863557]