[{"data":1,"prerenderedAt":2052},["ShallowReactive",2],{"blog-go-generics":3,"blog-all-for-related":1586},{"id":4,"title":5,"author":6,"body":7,"cardAlt":5,"categories":1571,"description":1574,"draft":1575,"extension":1576,"headerImage":1577,"keywords":1578,"meta":1579,"name":1580,"navigation":145,"path":1581,"seo":1582,"series":6,"stem":1583,"updated":6,"year":1584,"__hash__":1585},"blog\u002Fblog\u002Fgo-generics.md","Introduction to Generics in Go",null,{"type":8,"value":9,"toc":1563},"minimark",[10,23,26,29,34,45,48,110,121,267,270,417,424,447,450,558,565,752,755,819,822,835,838,840,844,854,992,995,1186,1189,1240,1243,1463,1465,1469,1472,1474,1478,1503,1508,1531,1540,1542,1545,1554,1559],[11,12,13,14,18,19,22],"p",{},"Given that Go is a typed language, you provide data types whenever you declare variables, functional arguments and return types. With generics, you can declare and use functions or types that are written to work with any of a set of types provided by calling code. Before generics you could use ",[15,16,17],"code",{},"interface"," or another common pattern was using ",[15,20,21],{},"map[string]interface"," to support dynamic inputs (example in JSON parsing).",[11,24,25],{},"Generics help in forcing static typing that gets missed when using interface. You need to maintain type conversions and handle errors related to it. It allows to reuse certain logic of code for different types of inputs.",[27,28],"hr",{},[30,31,33],"h2",{"id":32},"solving-the-non-generic-way","Solving the non-generic way",[11,35,36,40,41,44],{},[37,38,39],"strong",{},"Prerequisite:"," Installation of Go 1.18 or later. You can check current version using ",[15,42,43],{},"go version"," command.",[11,46,47],{},"Let's get the setup done quickly so that we can deep dive into making our code generic.",[49,50,55],"pre",{"className":51,"code":52,"language":53,"meta":54,"style":54},"language-bash shiki shiki-themes github-light github-dark","mkdir learn_generics\ncd learn_generics\ngo mod init learn_generics\nmkdir generics\ntouch main.go\n","bash","",[15,56,57,70,79,93,101],{"__ignoreMap":54},[58,59,62,66],"span",{"class":60,"line":61},"line",1,[58,63,65],{"class":64},"sScJk","mkdir",[58,67,69],{"class":68},"sZZnC"," learn_generics\n",[58,71,73,77],{"class":60,"line":72},2,[58,74,76],{"class":75},"sj4cs","cd",[58,78,69],{"class":68},[58,80,82,85,88,91],{"class":60,"line":81},3,[58,83,84],{"class":64},"go",[58,86,87],{"class":68}," mod",[58,89,90],{"class":68}," init",[58,92,69],{"class":68},[58,94,96,98],{"class":60,"line":95},4,[58,97,65],{"class":64},[58,99,100],{"class":68}," generics\n",[58,102,104,107],{"class":60,"line":103},5,[58,105,106],{"class":64},"touch",[58,108,109],{"class":68}," main.go\n",[11,111,112,113,116,117,120],{},"Now open your favourite editor and let's add simple functionality of reversing a string array. Let's create a ",[15,114,115],{},"reverse.go"," inside our ",[15,118,119],{},"generics"," directory and add following code.",[49,122,125],{"className":123,"code":124,"language":84,"meta":54,"style":54},"language-go shiki shiki-themes github-light github-dark","\u002F\u002F non_generic.go\npackage generics\n\nfunc ReverseString(input []string) []string {\n    for i, j := 0, len(input)-1; i \u003C j; i, j = i+1, j-1 {\n        input[i], input[j] = input[j], input[i]\n    }\n    return input\n}\n",[15,126,127,133,141,147,177,235,246,252,261],{"__ignoreMap":54},[58,128,129],{"class":60,"line":61},[58,130,132],{"class":131},"sJ8bj","\u002F\u002F non_generic.go\n",[58,134,135,139],{"class":60,"line":72},[58,136,138],{"class":137},"szBVR","package",[58,140,100],{"class":64},[58,142,143],{"class":60,"line":81},[58,144,146],{"emptyLinePlaceholder":145},true,"\n",[58,148,149,152,155,159,163,166,169,172,174],{"class":60,"line":95},[58,150,151],{"class":137},"func",[58,153,154],{"class":64}," ReverseString",[58,156,158],{"class":157},"sVt8B","(",[58,160,162],{"class":161},"s4XuR","input",[58,164,165],{"class":157}," []",[58,167,168],{"class":137},"string",[58,170,171],{"class":157},") []",[58,173,168],{"class":137},[58,175,176],{"class":157}," {\n",[58,178,179,182,185,188,191,194,197,200,203,206,209,212,215,218,221,224,226,229,231,233],{"class":60,"line":103},[58,180,181],{"class":137},"    for",[58,183,184],{"class":157}," i, j ",[58,186,187],{"class":137},":=",[58,189,190],{"class":75}," 0",[58,192,193],{"class":157},", ",[58,195,196],{"class":64},"len",[58,198,199],{"class":157},"(input)",[58,201,202],{"class":137},"-",[58,204,205],{"class":75},"1",[58,207,208],{"class":157},"; i ",[58,210,211],{"class":137},"\u003C",[58,213,214],{"class":157}," j; i, j ",[58,216,217],{"class":137},"=",[58,219,220],{"class":157}," i",[58,222,223],{"class":137},"+",[58,225,205],{"class":75},[58,227,228],{"class":157},", j",[58,230,202],{"class":137},[58,232,205],{"class":75},[58,234,176],{"class":157},[58,236,238,241,243],{"class":60,"line":237},6,[58,239,240],{"class":157},"        input[i], input[j] ",[58,242,217],{"class":137},[58,244,245],{"class":157}," input[j], input[i]\n",[58,247,249],{"class":60,"line":248},7,[58,250,251],{"class":157},"    }\n",[58,253,255,258],{"class":60,"line":254},8,[58,256,257],{"class":137},"    return",[58,259,260],{"class":157}," input\n",[58,262,264],{"class":60,"line":263},9,[58,265,266],{"class":157},"}\n",[11,268,269],{},"We'll run this from our main to verify if it's working as expected.",[49,271,273],{"className":123,"code":272,"language":84,"meta":54,"style":54},"\u002F\u002F main.go\npackage main\n\nimport (\n    \"blog_codes\u002Fgenerics\"\n    \"fmt\"\n)\n\nfunc main() {\n  inputStringArr := []string{\"a\", \"b\", \"c\", \"d\", \"e\"}\n    outputStringArr := generics.ReverseString(inputStringArr)\n    fmt.Println(\"Reverse string array: \", outputStringArr)\n}\n",[15,274,275,280,287,291,299,310,319,324,328,338,378,395,412],{"__ignoreMap":54},[58,276,277],{"class":60,"line":61},[58,278,279],{"class":131},"\u002F\u002F main.go\n",[58,281,282,284],{"class":60,"line":72},[58,283,138],{"class":137},[58,285,286],{"class":64}," main\n",[58,288,289],{"class":60,"line":81},[58,290,146],{"emptyLinePlaceholder":145},[58,292,293,296],{"class":60,"line":95},[58,294,295],{"class":137},"import",[58,297,298],{"class":157}," (\n",[58,300,301,304,307],{"class":60,"line":103},[58,302,303],{"class":68},"    \"",[58,305,306],{"class":64},"blog_codes\u002Fgenerics",[58,308,309],{"class":68},"\"\n",[58,311,312,314,317],{"class":60,"line":237},[58,313,303],{"class":68},[58,315,316],{"class":64},"fmt",[58,318,309],{"class":68},[58,320,321],{"class":60,"line":248},[58,322,323],{"class":157},")\n",[58,325,326],{"class":60,"line":254},[58,327,146],{"emptyLinePlaceholder":145},[58,329,330,332,335],{"class":60,"line":263},[58,331,151],{"class":137},[58,333,334],{"class":64}," main",[58,336,337],{"class":157},"() {\n",[58,339,341,344,346,348,350,353,356,358,361,363,366,368,371,373,376],{"class":60,"line":340},10,[58,342,343],{"class":157},"  inputStringArr ",[58,345,187],{"class":137},[58,347,165],{"class":157},[58,349,168],{"class":137},[58,351,352],{"class":157},"{",[58,354,355],{"class":68},"\"a\"",[58,357,193],{"class":157},[58,359,360],{"class":68},"\"b\"",[58,362,193],{"class":157},[58,364,365],{"class":68},"\"c\"",[58,367,193],{"class":157},[58,369,370],{"class":68},"\"d\"",[58,372,193],{"class":157},[58,374,375],{"class":68},"\"e\"",[58,377,266],{"class":157},[58,379,381,384,386,389,392],{"class":60,"line":380},11,[58,382,383],{"class":157},"    outputStringArr ",[58,385,187],{"class":137},[58,387,388],{"class":157}," generics.",[58,390,391],{"class":64},"ReverseString",[58,393,394],{"class":157},"(inputStringArr)\n",[58,396,398,401,404,406,409],{"class":60,"line":397},12,[58,399,400],{"class":157},"    fmt.",[58,402,403],{"class":64},"Println",[58,405,158],{"class":157},[58,407,408],{"class":68},"\"Reverse string array: \"",[58,410,411],{"class":157},", outputStringArr)\n",[58,413,415],{"class":60,"line":414},13,[58,416,266],{"class":157},[11,418,419,420,423],{},"From you command line run ",[15,421,422],{},"go run main.go"," to execute our code.",[49,425,427],{"className":51,"code":426,"language":53,"meta":54,"style":54},"$ go run main.go\n[e d c b a]\n",[15,428,429,442],{"__ignoreMap":54},[58,430,431,434,437,440],{"class":60,"line":61},[58,432,433],{"class":64},"$",[58,435,436],{"class":68}," go",[58,438,439],{"class":68}," run",[58,441,109],{"class":68},[58,443,444],{"class":60,"line":72},[58,445,446],{"class":157},"[e d c b a]\n",[11,448,449],{},"Simple enough, right? Let's also add functionality to reverse integer arrays?",[49,451,453],{"className":123,"code":452,"language":84,"meta":54,"style":54},"\u002F\u002F non_generic.go\n\n\u002F\u002F earlier code ...\n\nfunc ReverseInteger(input []int) []int {\n    for i, j := 0, len(input)-1; i \u003C j; i, j = i+1, j-1 {\n        input[i], input[j] = input[j], input[i]\n    }\n    return input\n}\n",[15,454,455,459,463,468,472,494,536,544,548,554],{"__ignoreMap":54},[58,456,457],{"class":60,"line":61},[58,458,132],{"class":131},[58,460,461],{"class":60,"line":72},[58,462,146],{"emptyLinePlaceholder":145},[58,464,465],{"class":60,"line":81},[58,466,467],{"class":131},"\u002F\u002F earlier code ...\n",[58,469,470],{"class":60,"line":95},[58,471,146],{"emptyLinePlaceholder":145},[58,473,474,476,479,481,483,485,488,490,492],{"class":60,"line":103},[58,475,151],{"class":137},[58,477,478],{"class":64}," ReverseInteger",[58,480,158],{"class":157},[58,482,162],{"class":161},[58,484,165],{"class":157},[58,486,487],{"class":137},"int",[58,489,171],{"class":157},[58,491,487],{"class":137},[58,493,176],{"class":157},[58,495,496,498,500,502,504,506,508,510,512,514,516,518,520,522,524,526,528,530,532,534],{"class":60,"line":237},[58,497,181],{"class":137},[58,499,184],{"class":157},[58,501,187],{"class":137},[58,503,190],{"class":75},[58,505,193],{"class":157},[58,507,196],{"class":64},[58,509,199],{"class":157},[58,511,202],{"class":137},[58,513,205],{"class":75},[58,515,208],{"class":157},[58,517,211],{"class":137},[58,519,214],{"class":157},[58,521,217],{"class":137},[58,523,220],{"class":157},[58,525,223],{"class":137},[58,527,205],{"class":75},[58,529,228],{"class":157},[58,531,202],{"class":137},[58,533,205],{"class":75},[58,535,176],{"class":157},[58,537,538,540,542],{"class":60,"line":248},[58,539,240],{"class":157},[58,541,217],{"class":137},[58,543,245],{"class":157},[58,545,546],{"class":60,"line":254},[58,547,251],{"class":157},[58,549,550,552],{"class":60,"line":263},[58,551,257],{"class":137},[58,553,260],{"class":157},[58,555,556],{"class":60,"line":340},[58,557,266],{"class":157},[11,559,560,561,564],{},"We'll also update ",[15,562,563],{},"main.go"," to get this runnning.",[49,566,568],{"className":123,"code":567,"language":84,"meta":54,"style":54},"package main\n\nimport (\n    \"blog_codes\u002Fgenerics\"\n    \"fmt\"\n)\n\nfunc main() {\n    inputStringArr := []string{\"a\", \"b\", \"c\", \"d\", \"e\"}\n    outputStringArr := generics.ReverseString(inputStringArr)\n    fmt.Println(\"Reverse string array: \", outputStringArr)\n\n    inputIntArr := []int{1, 2, 3, 4, 5}\n    outputIntArr := generics.ReverseInteger(inputIntArr)\n    fmt.Println(\"Reverse integer array: \", outputIntArr)\n}\n",[15,569,570,576,580,586,594,602,606,610,618,651,663,675,679,716,732,747],{"__ignoreMap":54},[58,571,572,574],{"class":60,"line":61},[58,573,138],{"class":137},[58,575,286],{"class":64},[58,577,578],{"class":60,"line":72},[58,579,146],{"emptyLinePlaceholder":145},[58,581,582,584],{"class":60,"line":81},[58,583,295],{"class":137},[58,585,298],{"class":157},[58,587,588,590,592],{"class":60,"line":95},[58,589,303],{"class":68},[58,591,306],{"class":64},[58,593,309],{"class":68},[58,595,596,598,600],{"class":60,"line":103},[58,597,303],{"class":68},[58,599,316],{"class":64},[58,601,309],{"class":68},[58,603,604],{"class":60,"line":237},[58,605,323],{"class":157},[58,607,608],{"class":60,"line":248},[58,609,146],{"emptyLinePlaceholder":145},[58,611,612,614,616],{"class":60,"line":254},[58,613,151],{"class":137},[58,615,334],{"class":64},[58,617,337],{"class":157},[58,619,620,623,625,627,629,631,633,635,637,639,641,643,645,647,649],{"class":60,"line":263},[58,621,622],{"class":157},"    inputStringArr ",[58,624,187],{"class":137},[58,626,165],{"class":157},[58,628,168],{"class":137},[58,630,352],{"class":157},[58,632,355],{"class":68},[58,634,193],{"class":157},[58,636,360],{"class":68},[58,638,193],{"class":157},[58,640,365],{"class":68},[58,642,193],{"class":157},[58,644,370],{"class":68},[58,646,193],{"class":157},[58,648,375],{"class":68},[58,650,266],{"class":157},[58,652,653,655,657,659,661],{"class":60,"line":340},[58,654,383],{"class":157},[58,656,187],{"class":137},[58,658,388],{"class":157},[58,660,391],{"class":64},[58,662,394],{"class":157},[58,664,665,667,669,671,673],{"class":60,"line":380},[58,666,400],{"class":157},[58,668,403],{"class":64},[58,670,158],{"class":157},[58,672,408],{"class":68},[58,674,411],{"class":157},[58,676,677],{"class":60,"line":397},[58,678,146],{"emptyLinePlaceholder":145},[58,680,681,684,686,688,690,692,694,696,699,701,704,706,709,711,714],{"class":60,"line":414},[58,682,683],{"class":157},"    inputIntArr ",[58,685,187],{"class":137},[58,687,165],{"class":157},[58,689,487],{"class":137},[58,691,352],{"class":157},[58,693,205],{"class":75},[58,695,193],{"class":157},[58,697,698],{"class":75},"2",[58,700,193],{"class":157},[58,702,703],{"class":75},"3",[58,705,193],{"class":157},[58,707,708],{"class":75},"4",[58,710,193],{"class":157},[58,712,713],{"class":75},"5",[58,715,266],{"class":157},[58,717,719,722,724,726,729],{"class":60,"line":718},14,[58,720,721],{"class":157},"    outputIntArr ",[58,723,187],{"class":137},[58,725,388],{"class":157},[58,727,728],{"class":64},"ReverseInteger",[58,730,731],{"class":157},"(inputIntArr)\n",[58,733,735,737,739,741,744],{"class":60,"line":734},15,[58,736,400],{"class":157},[58,738,403],{"class":64},[58,740,158],{"class":157},[58,742,743],{"class":68},"\"Reverse integer array: \"",[58,745,746],{"class":157},", outputIntArr)\n",[58,748,750],{"class":60,"line":749},16,[58,751,266],{"class":157},[11,753,754],{},"The output we now get",[49,756,758],{"className":51,"code":757,"language":53,"meta":54,"style":54},"$ go run main.go\nReverse string array:  [e d c b a]\nReverse integer array:  [5 4 3 2 1]\n",[15,759,760,770,796],{"__ignoreMap":54},[58,761,762,764,766,768],{"class":60,"line":61},[58,763,433],{"class":64},[58,765,436],{"class":68},[58,767,439],{"class":68},[58,769,109],{"class":68},[58,771,772,775,778,781,784,787,790,793],{"class":60,"line":72},[58,773,774],{"class":64},"Reverse",[58,776,777],{"class":68}," string",[58,779,780],{"class":68}," array:",[58,782,783],{"class":157},"  [e ",[58,785,786],{"class":68},"d",[58,788,789],{"class":68}," c",[58,791,792],{"class":68}," b",[58,794,795],{"class":68}," a]\n",[58,797,798,800,803,805,808,810,813,816],{"class":60,"line":81},[58,799,774],{"class":64},[58,801,802],{"class":68}," integer",[58,804,780],{"class":68},[58,806,807],{"class":157},"  [5 ",[58,809,708],{"class":75},[58,811,812],{"class":75}," 3",[58,814,815],{"class":75}," 2",[58,817,818],{"class":68}," 1]\n",[11,820,821],{},"Ok, we did some basic implementation for reversing an array. What's the point? There are some key points to notice here:",[823,824,825,829,832],"ul",{},[826,827,828],"li",{},"Can we use same function for both data type? - No, input and type is string struct vs int struct. See that's why we called it non-generic.",[826,830,831],{},"Is there a similarity you see in both reverse functions? - Yes, logic for both implementations are actually same. We're iterating over array and swapping values to reverse it.",[826,833,834],{},"Can we write a common reverse function that works out not just for string or integer rather other data types as well?",[11,836,837],{},"Yes, now we can do this quite easily in Go using generics.",[27,839],{},[30,841,843],{"id":842},"solving-the-generic-way","Solving the Generic way",[11,845,846,847,850,851,853],{},"We'll create a ",[15,848,849],{},"generic.go"," file in our ",[15,852,119],{}," directory and update it with a generic reverse method. Don't worry if you don't get it at first look. We'll go through the code together.",[49,855,857],{"className":123,"code":856,"language":84,"meta":54,"style":54},"\u002F\u002F generic.go\npackage generics\n\nfunc ReverseGeneric[T any](input []T) []T {\n    l := len(input)\n    output := make([]T, l)\n\n    for i, ele := range input {\n        output[l-i-1] = ele\n    }\n    return output\n}\n",[15,858,859,864,870,874,905,918,936,940,955,977,981,988],{"__ignoreMap":54},[58,860,861],{"class":60,"line":61},[58,862,863],{"class":131},"\u002F\u002F generic.go\n",[58,865,866,868],{"class":60,"line":72},[58,867,138],{"class":137},[58,869,100],{"class":64},[58,871,872],{"class":60,"line":81},[58,873,146],{"emptyLinePlaceholder":145},[58,875,876,878,881,884,887,890,893,895,897,899,901,903],{"class":60,"line":95},[58,877,151],{"class":137},[58,879,880],{"class":64}," ReverseGeneric",[58,882,883],{"class":157},"[",[58,885,886],{"class":161},"T",[58,888,889],{"class":64}," any",[58,891,892],{"class":157},"](",[58,894,162],{"class":161},[58,896,165],{"class":157},[58,898,886],{"class":64},[58,900,171],{"class":157},[58,902,886],{"class":64},[58,904,176],{"class":157},[58,906,907,910,912,915],{"class":60,"line":103},[58,908,909],{"class":157},"    l ",[58,911,187],{"class":137},[58,913,914],{"class":64}," len",[58,916,917],{"class":157},"(input)\n",[58,919,920,923,925,928,931,933],{"class":60,"line":237},[58,921,922],{"class":157},"    output ",[58,924,187],{"class":137},[58,926,927],{"class":64}," make",[58,929,930],{"class":157},"([]",[58,932,886],{"class":64},[58,934,935],{"class":157},", l)\n",[58,937,938],{"class":60,"line":248},[58,939,146],{"emptyLinePlaceholder":145},[58,941,942,944,947,949,952],{"class":60,"line":254},[58,943,181],{"class":137},[58,945,946],{"class":157}," i, ele ",[58,948,187],{"class":137},[58,950,951],{"class":137}," range",[58,953,954],{"class":157}," input {\n",[58,956,957,960,962,965,967,969,972,974],{"class":60,"line":263},[58,958,959],{"class":157},"        output[l",[58,961,202],{"class":137},[58,963,964],{"class":157},"i",[58,966,202],{"class":137},[58,968,205],{"class":75},[58,970,971],{"class":157},"] ",[58,973,217],{"class":137},[58,975,976],{"class":157}," ele\n",[58,978,979],{"class":60,"line":340},[58,980,251],{"class":157},[58,982,983,985],{"class":60,"line":380},[58,984,257],{"class":137},[58,986,987],{"class":157}," output\n",[58,989,990],{"class":60,"line":397},[58,991,266],{"class":157},[11,993,994],{},"We'll use the same arrays but now use our generic reverse function.",[49,996,998],{"className":123,"code":997,"language":84,"meta":54,"style":54},"\u002F\u002F main.go\npackage main\n\nimport (\n    \"blog_codes\u002Fgenerics\"\n    \"fmt\"\n)\n\nfunc main() {\n    inputStringArr := []string{\"a\", \"b\", \"c\", \"d\", \"e\"}\n    inputIntArr := []int{1, 2, 3, 4, 5}\n    \n    genericOutput := generics.ReverseGeneric(inputStringArr)\n    fmt.Println(\"Reversed string array (generic way): \", genericOutput)\n    \n  genericIntOutput := generics.ReverseGeneric(inputIntArr)\n    fmt.Println(\"Reversed integer array (generic way): \", genericIntOutput)\n}\n\n",[15,999,1000,1004,1010,1014,1020,1028,1036,1040,1044,1052,1084,1116,1121,1135,1149,1153,1166,1181],{"__ignoreMap":54},[58,1001,1002],{"class":60,"line":61},[58,1003,279],{"class":131},[58,1005,1006,1008],{"class":60,"line":72},[58,1007,138],{"class":137},[58,1009,286],{"class":64},[58,1011,1012],{"class":60,"line":81},[58,1013,146],{"emptyLinePlaceholder":145},[58,1015,1016,1018],{"class":60,"line":95},[58,1017,295],{"class":137},[58,1019,298],{"class":157},[58,1021,1022,1024,1026],{"class":60,"line":103},[58,1023,303],{"class":68},[58,1025,306],{"class":64},[58,1027,309],{"class":68},[58,1029,1030,1032,1034],{"class":60,"line":237},[58,1031,303],{"class":68},[58,1033,316],{"class":64},[58,1035,309],{"class":68},[58,1037,1038],{"class":60,"line":248},[58,1039,323],{"class":157},[58,1041,1042],{"class":60,"line":254},[58,1043,146],{"emptyLinePlaceholder":145},[58,1045,1046,1048,1050],{"class":60,"line":263},[58,1047,151],{"class":137},[58,1049,334],{"class":64},[58,1051,337],{"class":157},[58,1053,1054,1056,1058,1060,1062,1064,1066,1068,1070,1072,1074,1076,1078,1080,1082],{"class":60,"line":340},[58,1055,622],{"class":157},[58,1057,187],{"class":137},[58,1059,165],{"class":157},[58,1061,168],{"class":137},[58,1063,352],{"class":157},[58,1065,355],{"class":68},[58,1067,193],{"class":157},[58,1069,360],{"class":68},[58,1071,193],{"class":157},[58,1073,365],{"class":68},[58,1075,193],{"class":157},[58,1077,370],{"class":68},[58,1079,193],{"class":157},[58,1081,375],{"class":68},[58,1083,266],{"class":157},[58,1085,1086,1088,1090,1092,1094,1096,1098,1100,1102,1104,1106,1108,1110,1112,1114],{"class":60,"line":380},[58,1087,683],{"class":157},[58,1089,187],{"class":137},[58,1091,165],{"class":157},[58,1093,487],{"class":137},[58,1095,352],{"class":157},[58,1097,205],{"class":75},[58,1099,193],{"class":157},[58,1101,698],{"class":75},[58,1103,193],{"class":157},[58,1105,703],{"class":75},[58,1107,193],{"class":157},[58,1109,708],{"class":75},[58,1111,193],{"class":157},[58,1113,713],{"class":75},[58,1115,266],{"class":157},[58,1117,1118],{"class":60,"line":397},[58,1119,1120],{"class":157},"    \n",[58,1122,1123,1126,1128,1130,1133],{"class":60,"line":414},[58,1124,1125],{"class":157},"    genericOutput ",[58,1127,187],{"class":137},[58,1129,388],{"class":157},[58,1131,1132],{"class":64},"ReverseGeneric",[58,1134,394],{"class":157},[58,1136,1137,1139,1141,1143,1146],{"class":60,"line":718},[58,1138,400],{"class":157},[58,1140,403],{"class":64},[58,1142,158],{"class":157},[58,1144,1145],{"class":68},"\"Reversed string array (generic way): \"",[58,1147,1148],{"class":157},", genericOutput)\n",[58,1150,1151],{"class":60,"line":734},[58,1152,1120],{"class":157},[58,1154,1155,1158,1160,1162,1164],{"class":60,"line":749},[58,1156,1157],{"class":157},"  genericIntOutput ",[58,1159,187],{"class":137},[58,1161,388],{"class":157},[58,1163,1132],{"class":64},[58,1165,731],{"class":157},[58,1167,1169,1171,1173,1175,1178],{"class":60,"line":1168},17,[58,1170,400],{"class":157},[58,1172,403],{"class":64},[58,1174,158],{"class":157},[58,1176,1177],{"class":68},"\"Reversed integer array (generic way): \"",[58,1179,1180],{"class":157},", genericIntOutput)\n",[58,1182,1184],{"class":60,"line":1183},18,[58,1185,266],{"class":157},[11,1187,1188],{},"On running now, you'll see the following output.",[49,1190,1192],{"className":51,"code":1191,"language":53,"meta":54,"style":54},"Reversed string array (generic way):  [a b c d e]\nReversed integer array (generic way):  [1 2 3 4 5]\n",[15,1193,1194,1213],{"__ignoreMap":54},[58,1195,1196,1199,1201,1204,1207,1210],{"class":60,"line":61},[58,1197,1198],{"class":64},"Reversed",[58,1200,777],{"class":68},[58,1202,1203],{"class":68}," array",[58,1205,1206],{"class":157}," (generic ",[58,1208,1209],{"class":68},"way",[58,1211,1212],{"class":157},"):  [a b c d e]\n",[58,1214,1215,1217,1219,1221,1223,1225,1228,1230,1232,1234,1237],{"class":60,"line":72},[58,1216,1198],{"class":64},[58,1218,802],{"class":68},[58,1220,1203],{"class":68},[58,1222,1206],{"class":157},[58,1224,1209],{"class":68},[58,1226,1227],{"class":157},"):  [",[58,1229,205],{"class":75},[58,1231,815],{"class":75},[58,1233,812],{"class":75},[58,1235,1236],{"class":75}," 4",[58,1238,1239],{"class":157}," 5]\n",[11,1241,1242],{},"Yay 🎉 You just wrote your first generic code. Time to deep dive on what's happening here.",[823,1244,1245,1262,1268,1278,1284,1299,1313],{},[826,1246,1247,1250,1251,1254,1255,1258,1259,1261],{},[15,1248,1249],{},"[T any]"," - In our function declaration we added this. These are abstract data types that we call ",[15,1252,1253],{},"type parameters"," which help in making our functions generic and  allowing it to work with arguments of different types. The type parameters are added withing square brackets. That's how go knows that these are type params. Here we've use ",[15,1256,1257],{},"any"," as our type that means our function can support any data type inputs. ",[15,1260,1257],{}," is an alias for interface{} which basically allows any type.",[826,1263,1264,1267],{},[15,1265,1266],{},"[s []T]"," - Here we define input params to our function which says that I can accept array of type T (which is any as defined above).",[826,1269,1270,1273,1274,1277],{},[15,1271,1272],{},"output := make([]T, l)"," - The logic is similar only difference here is that we're creating a new struct of input type T and reversing the input array. This is same as writing ",[15,1275,1276],{},"output := make([]int, l)"," for integer array.",[826,1279,1280,1283],{},[37,1281,1282],{},"Note:","  Type parameter you've define must support all the operations the generic code is performing on it.",[826,1285,1286,1287,1290,1291,1294,1295,1298],{},"There are certain predefined constraints like ",[15,1288,1289],{},"comparable"," in Go. It only allows data types whose values may be used as an operand of the comparison operators ",[15,1292,1293],{},"=="," and ",[15,1296,1297],{},"!=",". Instead of allowing any data type this restricts on what input it can support. These type contraints are essentially interface types.",[826,1300,1301,1304,1305,1308,1309,1312],{},[37,1302,1303],{},"Question:"," should we use ",[15,1306,1307],{},"T comparable"," or ",[15,1310,1311],{},"T any"," ? Or both will work? I'll leave this as an exercise for you.",[826,1314,1315,1316,1318,1319,1321,1322],{},"You might wonder but ",[15,1317,1257],{}," , ",[15,1320,1289],{}," etc would just cover certain cases. What if i want to control what types to allow. Generics provides a way to solve that as well. Continuing our example, we could have created an interface and used that instead.",[49,1323,1325],{"className":123,"code":1324,"language":84,"meta":54,"style":54},"type MyDataTypes interface {\n    string | int | int64\n}\n\nfunc ReverseGeneric[T MyDataType](input []T) []T {\n    l := len(input)\n    output := make([]T, l)\n\n    for i, ele := range input {\n        output[l-i-1] = ele\n    }\n    return output\n}\n",[15,1326,1327,1340,1356,1360,1364,1391,1401,1415,1419,1431,1449,1453,1459],{"__ignoreMap":54},[58,1328,1329,1332,1335,1338],{"class":60,"line":61},[58,1330,1331],{"class":137},"type",[58,1333,1334],{"class":64}," MyDataTypes",[58,1336,1337],{"class":137}," interface",[58,1339,176],{"class":157},[58,1341,1342,1345,1348,1351,1353],{"class":60,"line":72},[58,1343,1344],{"class":137},"    string",[58,1346,1347],{"class":137}," |",[58,1349,1350],{"class":137}," int",[58,1352,1347],{"class":137},[58,1354,1355],{"class":137}," int64\n",[58,1357,1358],{"class":60,"line":81},[58,1359,266],{"class":157},[58,1361,1362],{"class":60,"line":95},[58,1363,146],{"emptyLinePlaceholder":145},[58,1365,1366,1368,1370,1372,1374,1377,1379,1381,1383,1385,1387,1389],{"class":60,"line":103},[58,1367,151],{"class":137},[58,1369,880],{"class":64},[58,1371,883],{"class":157},[58,1373,886],{"class":161},[58,1375,1376],{"class":64}," MyDataType",[58,1378,892],{"class":157},[58,1380,162],{"class":161},[58,1382,165],{"class":157},[58,1384,886],{"class":64},[58,1386,171],{"class":157},[58,1388,886],{"class":64},[58,1390,176],{"class":157},[58,1392,1393,1395,1397,1399],{"class":60,"line":237},[58,1394,909],{"class":157},[58,1396,187],{"class":137},[58,1398,914],{"class":64},[58,1400,917],{"class":157},[58,1402,1403,1405,1407,1409,1411,1413],{"class":60,"line":248},[58,1404,922],{"class":157},[58,1406,187],{"class":137},[58,1408,927],{"class":64},[58,1410,930],{"class":157},[58,1412,886],{"class":64},[58,1414,935],{"class":157},[58,1416,1417],{"class":60,"line":254},[58,1418,146],{"emptyLinePlaceholder":145},[58,1420,1421,1423,1425,1427,1429],{"class":60,"line":263},[58,1422,181],{"class":137},[58,1424,946],{"class":157},[58,1426,187],{"class":137},[58,1428,951],{"class":137},[58,1430,954],{"class":157},[58,1432,1433,1435,1437,1439,1441,1443,1445,1447],{"class":60,"line":340},[58,1434,959],{"class":157},[58,1436,202],{"class":137},[58,1438,964],{"class":157},[58,1440,202],{"class":137},[58,1442,205],{"class":75},[58,1444,971],{"class":157},[58,1446,217],{"class":137},[58,1448,976],{"class":157},[58,1450,1451],{"class":60,"line":380},[58,1452,251],{"class":157},[58,1454,1455,1457],{"class":60,"line":397},[58,1456,257],{"class":137},[58,1458,987],{"class":157},[58,1460,1461],{"class":60,"line":414},[58,1462,266],{"class":157},[27,1464],{},[30,1466,1468],{"id":1467},"should-i-use-generics","Should I use Generics?",[11,1470,1471],{},"Well, to be honest generics in go is still quite new. Though I personally love how easy it is to use but for a lot of cases using interface with implementations might be the easier way as the code starts getting more complex. Don't think of generics as something that will magically make your life 10x better. It's just another way to solve a problem. In all the prod codebases that I've worked related to Go, I'm yet to see generics code being used. Hopefully soon 🤞",[27,1473],{},[30,1475,1477],{"id":1476},"resources","Resources",[823,1479,1480,1489,1496],{},[826,1481,1482],{},[1483,1484,1488],"a",{"href":1485,"rel":1486},"https:\u002F\u002Fgo.dev\u002Fdoc\u002Ftutorial\u002Fgenerics",[1487],"nofollow","Go Official Tutorial",[826,1490,1491],{},[1483,1492,1495],{"href":1493,"rel":1494},"https:\u002F\u002Fbitfieldconsulting.com\u002Fgolang\u002Fgenerics",[1487],"Good Guide on Generics",[826,1497,1498],{},[1483,1499,1502],{"href":1500,"rel":1501},"https:\u002F\u002Fsecrethub.io\u002Fblog\u002Fgo-generics\u002F",[1487],"Real world use of Generics",[1504,1505,1507],"h3",{"id":1506},"books-to-learn-golang","Books to learn Golang",[823,1509,1510,1517,1524],{},[826,1511,1512],{},[1483,1513,1516],{"href":1514,"rel":1515},"https:\u002F\u002Famzn.to\u002F3fYLCqz",[1487],"Go Programming Language",[826,1518,1519],{},[1483,1520,1523],{"href":1521,"rel":1522},"https:\u002F\u002Famzn.to\u002F3s7fWS3",[1487],"Learning Go",[826,1525,1526],{},[1483,1527,1530],{"href":1528,"rel":1529},"https:\u002F\u002Famzn.to\u002F3t6PM37",[1487],"Go in Action",[11,1532,1533,1534,1539],{},"Liked the article? Consider ",[1483,1535,1538],{"href":1536,"rel":1537},"https:\u002F\u002Fwww.buymeacoffee.com\u002FchHAzigTb",[1487],"supporting me"," ☕️",[27,1541],{},[11,1543,1544],{},"I hope you learned something new. Feel free to suggest improvements ✔️",[11,1546,1547,1548,1553],{},"Follow me on ",[1483,1549,1552],{"href":1550,"rel":1551},"https:\u002F\u002Ftwitter.com\u002Fmkfeuhrer",[1487],"Twitter"," for updates and resources. Let's connect!",[11,1555,1556],{},[37,1557,1558],{},"Keep exploring 🔎 Keep learning 🚀",[1560,1561,1562],"style",{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}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 .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}",{"title":54,"searchDepth":72,"depth":72,"links":1564},[1565,1566,1567,1568],{"id":32,"depth":72,"text":33},{"id":842,"depth":72,"text":843},{"id":1467,"depth":72,"text":1468},{"id":1476,"depth":72,"text":1477,"children":1569},[1570],{"id":1506,"depth":81,"text":1507},[1572,1573],"Golang","Programming","Learn about generics in Golang, it's benefits and how to implement it in applications.",false,"md","blog\u002Fgo-generics\u002Fgo-generics-card.webp","generics go, generics in golang, golang generics example, golang generics any",{},"go-generics","\u002Fblog\u002Fgo-generics",{"title":5,"description":1574},"blog\u002Fgo-generics","2022-11-27","PyDRgsIgbDtzCJpbDl8tVl9Fn172WjY6lmupj3sNKs0",[1587,1594,1600,1608,1617,1624,1631,1638,1644,1650,1656,1662,1668,1677,1683,1690,1696,1702,1708,1714,1716,1722,1728,1734,1741,1748,1754,1760,1766,1772,1778,1784,1790,1796,1802,1808,1814,1820,1826,1833,1839,1845,1851,1858,1864,1870,1877,1884,1890,1897,1903,1910,1916,1923,1929,1935,1941,1947,1953,1959,1965,1971,1977,1983,1989,1995,2002,2008,2015,2021,2027,2033,2040,2046],{"path":1588,"title":1589,"description":1590,"categories":1591,"draft":145,"year":1593,"series":6},"\u002Fblog\u002Fai-assisted-workstation","Building an AI-Assisted Personal Workstation","How I built a personal AI workstation: markdown knowledge base, portable agent skills, handoff-driven sessions. What worked, what broke, what I would change.",[1592,1573],"Productivity","2026-08-26",{"path":1595,"title":1596,"description":1597,"categories":1598,"draft":1575,"year":1599,"series":6},"\u002Fblog\u002Faws-s3-golang","Uploading images to AWS S3 in Golang","In this tutorial I cover how to upload, fetch and manage other operations for objects on AWS S3 in Golang",[1572,1573],"2020-01-12",{"path":1601,"title":1602,"description":1603,"categories":1604,"draft":1575,"year":1607,"series":6},"\u002Fblog\u002Fbooks-for-engineers","Best Books for Software Engineers","Best Books to help you build you software engineering career - ranging from fundamentats, interview prep to productivity.",[1605,1606],"Books","Life","2021-12-26",{"path":1609,"title":1610,"description":1611,"categories":1612,"draft":1575,"year":1616,"series":6},"\u002Fblog\u002Fbuilding-acrons","Building Acrons 🚀","Building Acrons, a one-stop tool to decode everyday acronyms like DIY, FOMO, and BRB without losing your flow.",[1613,1614,1615],"Side Projects","Web","Tools","2020-05-26",{"path":1618,"title":1619,"description":1620,"categories":1621,"draft":1575,"year":1623,"series":6},"\u002Fblog\u002Fcap-theorem","CAP Theorem Explained","Learn the concept and misconceptions around popular CAP theorem in system design.",[1622,1573],"System Design","2021-07-26",{"path":1625,"title":1626,"description":1627,"categories":1628,"draft":1575,"year":1630,"series":6},"\u002Fblog\u002Fcode-reviews","Code Review Checklist","Why code reviews matter, and best practices that catch bugs early and keep code quality high before merge.",[1629],"Engineering Principles","2020-07-20",{"path":1632,"title":1633,"description":1634,"categories":1635,"draft":1575,"year":1637,"series":6},"\u002Fblog\u002Fdark-mode","Add Dark mode to websites","Dark mode is ❤️️ Add it to your websites with little CSS and JS",[1636,1614],"Javascript","2020-07-04",{"path":1639,"title":1640,"description":1641,"categories":1642,"draft":1575,"year":1643,"series":6},"\u002Fblog\u002Fdate-time-golang","Working with Date and Time in Go","Learn how to use time in Golang - Multiple formats, locations and using date.",[1572,1573],"2020-10-09",{"path":1645,"title":1646,"description":1647,"categories":1648,"draft":1575,"year":1649,"series":6},"\u002Fblog\u002Fdefer-in-golang","Understanding Defer In Golang","Learn about defer keyword in golang and how it can help you avoid panics due to bugs.",[1572,1573],"2021-05-05",{"path":1651,"title":1652,"description":1653,"categories":1654,"draft":1575,"year":1655,"series":6},"\u002Fblog\u002Fenums-golang","Implementing Enums in Golang","Enums are a way to defined set of constant values. Learn how to implement enums in Go using iota with examples.",[1572,1573],"2021-12-18",{"path":1657,"title":1658,"description":1659,"categories":1660,"draft":1575,"year":1661,"series":6},"\u002Fblog\u002Fenvironment-variable-golang","Guide to Environment variables in Go","Learn what are environment variables and how to use them in Go",[1572,1573],"2020-08-14",{"path":1663,"title":1664,"description":1665,"categories":1666,"draft":1575,"year":1667,"series":6},"\u002Fblog\u002Ferror-handling-golang","Handle errors the right way — Golang","How to handle errors in golang to make your life easy",[1572,1573],"2020-01-30",{"path":1669,"title":1670,"description":1671,"categories":1672,"draft":1575,"year":1593,"series":1675},"\u002Fblog\u002Ffile-attack-field-guide","How File-Based Attacks Land: A Detection Engineer's Field Guide","A practical taxonomy of how malware and phishing arrive as files, why classic controls miss them, and how detection should think.",[1673,1674],"Security","Systems",{"name":1676,"part":61},"File Attack Deep Dives",{"path":1678,"title":1679,"description":1680,"categories":1681,"draft":1575,"year":1682,"series":6},"\u002Fblog\u002Ffile-upload-golang","Uploading Files in Golang with Multipart Request","Learn how to upload files from your client to server as a multipart request in Golang.",[1572,1573],"2021-03-13",{"path":1684,"title":1685,"description":1686,"categories":1687,"draft":1575,"year":1689,"series":6},"\u002Fblog\u002Fgit-branch","Git Branch 101","Branching is a new path of development that makes it a lot easier to build features. Learn why and how to use branching in git.",[1688,1573],"Git","2022-03-20",{"path":1691,"title":1692,"description":1693,"categories":1694,"draft":1575,"year":1695,"series":6},"\u002Fblog\u002Fgit-pull-request-template","Guide to Pull Request Templates","Improve collaboration and code reviews with pull request templates. Blog include PR template and how to create one on github\u002Fgitlab",[1688,1573],"2023-08-24",{"path":1697,"title":1698,"description":1699,"categories":1700,"draft":1575,"year":1701,"series":6},"\u002Fblog\u002Fgit-remove-sensitive-info","Securing Git: Remove Sensitive Information","Protect your code from security breaches by using BFG tool to remove sensitive information from Git history. Learn how to do it in this comprehensive guide.",[1688,1573],"2023-10-16",{"path":1703,"title":1704,"description":1705,"categories":1706,"draft":1575,"year":1707,"series":6},"\u002Fblog\u002Fgit-tags-explained","Git tags : Explained","What Git tags are, why and when to use them, and how to start tagging releases in your own projects.",[1688,1573],"2020-06-18",{"path":1709,"title":1710,"description":1711,"categories":1712,"draft":1575,"year":1713,"series":6},"\u002Fblog\u002Fgo-dependency-injection","Dependency Injection in Go using Wire","Learn about dependency injection, its benefits and how to implement it in Go services using wire",[1572,1573],"2022-11-26",{"path":1581,"title":5,"description":1574,"categories":1715,"draft":1575,"year":1584,"series":6},[1572,1573],{"path":1717,"title":1718,"description":1719,"categories":1720,"draft":1575,"year":1721,"series":6},"\u002Fblog\u002Fgo-in-memory-cache","Building In-Memory Cache in Go","Learn about in-memory caching in Golang, it's benefits and how to implement it with and without generics with a TTL(expiry).",[1572,1573],"2024-03-28",{"path":1723,"title":1724,"description":1725,"categories":1726,"draft":1575,"year":1727,"series":6},"\u002Fblog\u002Fgo-makefile","Ultimate Makefile for Golang","Boost your productivity and save time with ultimate Makefile for Golang projects.",[1572,1573],"2024-06-10",{"path":1729,"title":1730,"description":1731,"categories":1732,"draft":1575,"year":1733,"series":6},"\u002Fblog\u002Fgo-middleware","Mastering Middlewares in Golang","Learn about middlewares, their use cases and how to implement them in Golang applications",[1572,1573],"2022-03-13",{"path":1735,"title":1736,"description":1737,"categories":1738,"draft":1575,"year":1740,"series":6},"\u002Fblog\u002Fgo-naming-conventions","Naming Conventions in Golang","Why naming conventions matter in Go, with best practices and practical examples for clear, readable, maintainable code.",[1572,1573,1739],"Code Quality","2023-05-19",{"path":1742,"title":1743,"description":1744,"categories":1745,"draft":1575,"year":1747,"series":6},"\u002Fblog\u002Fgo-with-redis","Go with Redis","A practical introduction to using Redis with Golang to make your applications faster with in-memory data storage.",[1572,1746,1573],"Database","2020-05-03",{"path":1749,"title":1750,"description":1751,"categories":1752,"draft":1575,"year":1753,"series":6},"\u002Fblog\u002Fgolang-maps","Learn Maps in Golang (with examples)","A complete guide to maps in Golang: creating maps, adding and removing items, iterating, and how map equality works.",[1572,1573],"2020-09-10",{"path":1755,"title":1756,"description":1757,"categories":1758,"draft":1575,"year":1759,"series":6},"\u002Fblog\u002Fguide-to-cdn","Guide to Content Delivery Network","CDN is one of the backbone of modern world internet infrastructure. Learn about Content Delivery Network, it's working, types and benefits.",[1622,1573],"2022-01-23",{"path":1761,"title":1762,"description":1763,"categories":1764,"draft":1575,"year":1765,"series":6},"\u002Fblog\u002Fguide-to-rule-engines","Guide to Rule Engines","Rule Engines help in solving changing business requirements with ease. Learn all about Rule engines, it's working, benefits and how to implement one in Golang",[1572,1573],"2022-09-12",{"path":1767,"title":1768,"description":1769,"categories":1770,"draft":1575,"year":1771,"series":6},"\u002Fblog\u002Fhexagonal-architecture","Guide to Hexagonal Architecture","Learn how to design efficient application with hexagonal architecture with practical example",[1622,1573],"2020-12-13",{"path":1773,"title":1774,"description":1775,"categories":1776,"draft":1575,"year":1777,"series":6},"\u002Fblog\u002Fhttp-status-codes","Learn HTTP Status Codes","A tour of HTTP response status codes, what each class means, and when to use which code in your applications.",[1614,1573],"2020-07-30",{"path":1779,"title":1780,"description":1781,"categories":1782,"draft":1575,"year":1783,"series":6},"\u002Fblog\u002Fintroduction-to-goroutines","Introduction to Goroutines","Understand the basics of concurrency and learn how to work with Goroutines in golang.",[1572,1573],"2021-04-10",{"path":1785,"title":1786,"description":1787,"categories":1788,"draft":1575,"year":1789,"series":6},"\u002Fblog\u002Fjson-in-postgres-with-golang","Storing JSON in Postgres with Golang","Learn how to store JSON objects in Postgres and how to implement it in Golang.",[1573,1746,1572],"2021-02-13",{"path":1791,"title":1792,"description":1793,"categories":1794,"draft":1575,"year":1795,"series":6},"\u002Fblog\u002Fjson-web-token","Complete Guide to JWT","JSON Web Tokens are a very compact way to carry information. Learn about JWTs in depth, from its structure to when to use it.",[1573,1614],"2021-11-20",{"path":1797,"title":1798,"description":1799,"categories":1800,"draft":1575,"year":1801,"series":6},"\u002Fblog\u002Flearn-to-say-no","Learning to say No","Learn why it's important to say 'NO'. How it helps in increasing productivity and explore strategies for saying No",[1606,1605],"2022-04-09",{"path":1803,"title":1804,"description":1805,"categories":1806,"draft":1575,"year":1807,"series":6},"\u002Fblog\u002Flearn-unlearn-relearn","Learn - Unlearn - Relearn","Unlearning things to learn new is the way to grow. Discover how to do that!",[1592,1606],"2020-09-25",{"path":1809,"title":1810,"description":1811,"categories":1812,"draft":1575,"year":1813,"series":6},"\u002Fblog\u002Flinting-in-golang","Introduction to Linting in Go","Introduction to improving code quality using linting. Learn how to add linting in your Go projects.",[1572,1573],"2021-07-07",{"path":1815,"title":1816,"description":1817,"categories":1818,"draft":1575,"year":1819,"series":6},"\u002Fblog\u002Fload-balancing","Load Balancing 101","Complete guide on load balancers explaining the internal working and how does it help in making applications efficient.",[1622,1573],"2021-05-29",{"path":1821,"title":1822,"description":1823,"categories":1824,"draft":1575,"year":1825,"series":6},"\u002Fblog\u002Fmaking-decisions-the-right-way","Making Decisions: The right way","Decisions are hard! Learn how to make the right decisions always",[1592,1606],"2020-06-07",{"path":1827,"title":1828,"description":1829,"categories":1830,"draft":1575,"year":1832,"series":6},"\u002Fblog\u002Fmanage-logs-with-logrotate","Using Logrotate to manage logs","Learn how to use logrotate system utility to manage logs with example",[1831,1573],"Linux","2020-09-08",{"path":1834,"title":1835,"description":1836,"categories":1837,"draft":1575,"year":1838,"series":6},"\u002Fblog\u002Fmarshal-structs-golang","Marshal structs the right way: Golang","Why Golang marshals empty structs into your JSON instead of null, and how to marshal structs the right way.",[1572,1573],"2020-03-31",{"path":1840,"title":1841,"description":1842,"categories":1843,"draft":1575,"year":1844,"series":6},"\u002Fblog\u002Fnotes-almanack-naval","Book Notes : Almanack of Naval Ravikant","My notes\u002Fhighlights from Almanack of Naval Ravikant book by Eric Jorgenson",[1605,1606],"2020-10-17",{"path":1846,"title":1847,"description":1848,"categories":1849,"draft":1575,"year":1850,"series":6},"\u002Fblog\u002Fnotes-anything-you-want","Book Notes : Anything you want","My notes\u002Fhighlights from Anything you want book by Derek Sivers",[1605,1606],"2021-09-25",{"path":1852,"title":1853,"description":1854,"categories":1855,"draft":1575,"year":1857,"series":6},"\u002Fblog\u002Fnotes-getting-real","Book Notes : Getting Real","My notes and highlights from Getting Real by Jason Fried and David Heinemeier Hansson on building web applications.",[1605,1856],"Startups","2020-11-03",{"path":1859,"title":1860,"description":1861,"categories":1862,"draft":1575,"year":1863,"series":6},"\u002Fblog\u002Fnotes-hell-yeah-or-no","Book Notes : Hell Yeah or No","My notes\u002Fhighlights from Hell Yeah or No book by Derek Sivers",[1605,1606],"2020-09-16",{"path":1865,"title":1866,"description":1867,"categories":1868,"draft":1575,"year":1869,"series":6},"\u002Fblog\u002Fnotes-how-to-be-a-capitalist","Book Notes : How to Be a Capitalist Without Any Capital","My notes\u002Fhighlights from How to Be a Capitalist Without Any Capital by Nathan Latka",[1605,1856],"2020-01-07",{"path":1871,"title":1872,"description":1873,"categories":1874,"draft":1575,"year":1876,"series":6},"\u002Fblog\u002Fnotes-lean-b2b","Book Notes : Lean B2B","My notes and highlights from Lean B2B by Étienne Garbugli on assessing markets, building MVPs, and selling to businesses.",[1605,1875],"Entrepreneurship","2022-07-02",{"path":1878,"title":1879,"description":1880,"categories":1881,"draft":1575,"year":1883,"series":6},"\u002Fblog\u002Fnotes-lets-talk-money","Book Notes : Let's Talk Money","My notes and highlights from Let's Talk Money by Monica Halan on managing personal finances and savings.",[1605,1882],"Personal Finance","2021-02-26",{"path":1885,"title":1886,"description":1887,"categories":1888,"draft":1575,"year":1889,"series":6},"\u002Fblog\u002Fnotes-obviously-awesome","Book Notes : Obviously Awesome","My notes and highlights from Obviously Awesome by April Dunford on product positioning and marketing strategy.",[1605,1856],"2020-04-26",{"path":1891,"title":1892,"description":1893,"categories":1894,"draft":1575,"year":1896,"series":6},"\u002Fblog\u002Fnotes-refactoring-ui","Book Notes: Refactoring UI","My notes and highlights from Refactoring UI by Adam Wathan and Steve Schoger, full of practical design tips for engineers.",[1605,1895],"Design","2020-05-09",{"path":1898,"title":1899,"description":1900,"categories":1901,"draft":1575,"year":1902,"series":6},"\u002Fblog\u002Fnotes-rework","Book Notes: Rework","My notes and highlights from Rework by Jason Fried and David Heinemeier Hansson on a better way to succeed in business.",[1605,1856],"2021-04-14",{"path":1904,"title":1905,"description":1906,"categories":1907,"draft":1575,"year":1909,"series":6},"\u002Fblog\u002Fone-on-one-meetings","Guide to Effective 1:1 Meetings","One on One meetings are important for your personal & professional growth. Learn how to master 1:1s with your manager and peers.",[1908,1592],"Career","2023-03-05",{"path":1911,"title":1912,"description":1913,"categories":1914,"draft":1575,"year":1915,"series":6},"\u002Fblog\u002Fpersonal-okrs","Personal OKRs for Success","Why one should set personal OKRs and how to achieve success with them",[1592,1606],"2020-06-27",{"path":1917,"title":1918,"description":1919,"categories":1920,"draft":1575,"year":1922,"series":6},"\u002Fblog\u002Fpoker-tips","Poker Tips: Johns Hopkins Poker Class","Notes from Johns Hopkins poker course. This guide will help you improve in Poker and win some large pots.",[1606,1921],"Poker","2020-06-13",{"path":1924,"title":1925,"description":1926,"categories":1927,"draft":1575,"year":1928,"series":6},"\u002Fblog\u002Fpomodoro","Get work done: The Pomo Way","Learn to focus and get productive by following the Pomodoro Technique",[1592],"2020-10-24",{"path":1930,"title":1931,"description":1932,"categories":1933,"draft":1575,"year":1934,"series":6},"\u002Fblog\u002Fpostgres-constraints","Postgres Constraints","Constraints are line of defense for database. Explore various types of constrainsts in postgres",[1746,1573],"2020-11-07",{"path":1936,"title":1937,"description":1938,"categories":1939,"draft":1575,"year":1940,"series":6},"\u002Fblog\u002Fppf-explained","PPF Explained","Learn basics about Public Provident Fund and why you should invest",[1606,1882],"2020-12-24",{"path":1942,"title":1943,"description":1944,"categories":1945,"draft":1575,"year":1946,"series":6},"\u002Fblog\u002Fproductivity-chrome-extensions","Boost Productivity with Chrome Extensions","Utitizing chrome extensions to boost your productivity!",[1592,1615,1614],"2020-04-24",{"path":1948,"title":1949,"description":1950,"categories":1951,"draft":1575,"year":1952,"series":6},"\u002Fblog\u002Fproductivity-in-vscode","Improve your productivity with VS Code","Key VS Code features like the integrated terminal, shortcuts, and extensions that improved my everyday productivity.",[1592,1573],"2020-03-12",{"path":1954,"title":1955,"description":1956,"categories":1957,"draft":1575,"year":1958,"series":6},"\u002Fblog\u002Freading-101","Improving Reading 101","Why reading matters, how to build a reading habit, and what to read next - from my own journey into books.",[1605,1606],"2020-04-04",{"path":1960,"title":1961,"description":1962,"categories":1963,"draft":1575,"year":1964,"series":6},"\u002Fblog\u002Freverse-proxy","Understanding Reverse Proxy","Learn about reverse proxy, how it is different from forward proxy and explore advantages of using it in system design.",[1622,1573],"2021-10-03",{"path":1966,"title":1967,"description":1968,"categories":1969,"draft":1575,"year":1970,"series":6},"\u002Fblog\u002Frunning-periodic-background-task-golang","Running periodic background tasks in Golang","How to run periodic background tasks in Golang by combining cron-style scheduling with background execution.",[1572,1573],"2019-11-21",{"path":1972,"title":1973,"description":1974,"categories":1975,"draft":1575,"year":1976,"series":6},"\u002Fblog\u002Fsessions-in-golang","Sessions using Golang and Redis","How cookies and sessions work, and how to implement persistent login sessions in Golang using Redis.",[1572,1746,1573],"2020-02-25",{"path":1978,"title":1979,"description":1980,"categories":1981,"draft":1575,"year":1982,"series":6},"\u002Fblog\u002Fsolid-dry-kiss-yagni","Solid Dry Kiss Yagni","An introduction to the SOLID, DRY, KISS, and YAGNI principles and how they help you write cleaner, robust code.",[1629],"2020-07-17",{"path":1984,"title":1985,"description":1986,"categories":1987,"draft":1575,"year":1988,"series":6},"\u002Fblog\u002Fstack-in-golang","Implement Stack in Golang","Learn how to implement stack data structure in Golang (Full code)",[1572,1573],"2020-09-14",{"path":1990,"title":1991,"description":1992,"categories":1993,"draft":1575,"year":1994,"series":6},"\u002Fblog\u002Fstart-oss-today","Start your Open Source journey today","Start your OSS journey with intro to GIT. Participate in Hacktoberfest!",[1688,1573],"2020-09-19",{"path":1996,"title":1997,"description":1998,"categories":1999,"draft":1575,"year":2001,"series":6},"\u002Fblog\u002Fsticky-social-bar","Sticky social share component in HTML","Learn how to build a social media sharing component in HTML and add it to your website.",[1573,2000],"Frontend","2021-02-05",{"path":2003,"title":2004,"description":2005,"categories":2006,"draft":1575,"year":2007,"series":6},"\u002Fblog\u002Fterm-insurance","Term insurance Simplified","Everything you need to know before you buy a term insurance.",[1606,1882],"2020-11-29",{"path":2009,"title":2010,"description":2011,"categories":2012,"draft":1575,"year":2014,"series":6},"\u002Fblog\u002Fterminal-output-with-redirection","Handling terminal outputs with Redirection","Learn how to handle terminal outputs with Redirection and saving it to files",[1831,2013,1573],"Terminal","2020-09-06",{"path":2016,"title":2017,"description":2018,"categories":2019,"draft":1575,"year":2020,"series":6},"\u002Fblog\u002Fthink-and-grow-rich","Book Notes: Think and Grow Rich","My notes and highlights from Think and Grow Rich by Napoleon Hill, covering its process for building wealth.",[1605,1606],"2020-05-19",{"path":2022,"title":2023,"description":2024,"categories":2025,"draft":1575,"year":2026,"series":6},"\u002Fblog\u002Ftransactions-postgres-golang","Transactions on Postgres with Golang","Performing Postgres database operations in Golang with GORM, from basic queries to full transaction support.",[1572,1746,1573],"2020-03-18",{"path":2028,"title":2029,"description":2030,"categories":2031,"draft":1575,"year":2032,"series":6},"\u002Fblog\u002Fwaitgroups-in-golang","WaitGroups in Golang","Learn about WaitGroups in golang and how to use them to perform concurrent operations without blocking the main thread.",[1572,1573],"2022-05-31",{"path":2034,"title":2035,"description":2036,"categories":2037,"draft":1575,"year":2039,"series":6},"\u002Fblog\u002Fwhat-i-use","What I Use: Products and Softwares","List of what I use in my day to day life ranging from terminal, editors, softwares, devices to accessories",[1606,2038],"Tech","2024-06-01",{"path":2041,"title":2042,"description":2043,"categories":2044,"draft":1575,"year":2045,"series":6},"\u002Fblog\u002Fyear-in-review-2020","Year in Review: 2020","It's a wrap! 2020 was a crazy year, See how my year went!",[1606],"2020-12-31",{"path":2047,"title":2048,"description":2049,"categories":2050,"draft":1575,"year":2051,"series":6},"\u002Fblog\u002Fyear-in-review-2021","Year in Review: 2021","It's a wrap! 2021 was a mixed bag, full of ups and downs. Key Goal for 2022: Start now!",[1606],"2021-12-31",1788272170035]