[{"data":1,"prerenderedAt":2166},["ShallowReactive",2],{"blog-go-dependency-injection":3,"blog-all-for-related":1673},{"id":4,"title":5,"author":6,"body":7,"cardAlt":5,"categories":1659,"description":1661,"draft":1662,"extension":1663,"headerImage":1664,"keywords":1665,"meta":1666,"name":1667,"navigation":103,"path":1668,"seo":1669,"series":6,"stem":1670,"updated":6,"year":1671,"__hash__":1672},"blog\u002Fblog\u002Fgo-dependency-injection.md","Dependency Injection in Go using Wire",null,{"type":8,"value":9,"toc":1649},"minimark",[10,19,26,37,40,43,61,1645],[11,12,13,14,18],"p",{},"Dependency Injection(DI) is a technique used in programming that helps you to decouple the external logic of your implementation. A very common use case is to build APIs, use database to power these APIs, etc. But your logic in the implementation shouldn't really change if one of the data sources change right? This is where dependency injection ",[15,16,17],"strong",{},"helps in decoupling logic",". Therefore DI helps in producing flexible and loosely coupled code.",[11,20,21,22,25],{},"Talking in more technical terms - Dependency injection is a design pattern that decouples the ",[15,23,24],{},"usage of a particular object from its creation"," (i.e. time the object is initialized).",[11,27,28,29,36],{},"You might have heard of the popular ",[30,31,35],"a",{"href":32,"rel":33},"https:\u002F\u002Fwww.mohitkhare.com\u002Fblog\u002Fsolid-dry-kiss-yagni\u002F",[34],"nofollow","SOLID principle",". The 'D' in SOLID stands for dependency inversion which states that classes should be open to extension thereby they should depend on interface instead of concrete classes (avoid tight coupling).",[11,38,39],{},"You may ask but how does this help? Basically it allows you to switch easily the implementation of some dependency. For example you have a user service, you could change DB dependency from postgres to mongoDB or any other database. The same principle is used in unit testing where you use mock implementation to test instead of real one.",[11,41,42],{},"In Go terminology, the responsibility for building dependencies doesn't lie with struct rather on interfaces. This also enables to use different implementation of the interface based on use case.",[44,45,46],"blockquote",{},[11,47,48,49,54,55,60],{},"Do explore articles on ",[30,50,53],{"href":51,"rel":52},"https:\u002F\u002Fwww.mohitkhare.com\u002Fcategories\u002Fgolang",[34],"Golang"," and ",[30,56,59],{"href":57,"rel":58},"https:\u002F\u002Fwww.mohitkhare.com\u002Fcategories\u002Fsystem%20design",[34],"System Design",". You'll learn something new 💡",[62,63,64,67,72,75,581,587,589,594,597,1085,1092,1094,1098,1101,1123,1130,1222,1229,1326,1347,1353,1384,1390,1499,1505,1523,1525,1529,1535,1548,1556,1567,1569,1573,1590,1594,1617,1626,1628,1631,1640],"ads",{},[65,66],"hr",{},[68,69,71],"h2",{"id":70},"understanding-with-example","Understanding with Example",[11,73,74],{},"Let's begin with a basic code with some structs and functions.",[76,77,82],"pre",{"className":78,"code":79,"language":80,"meta":81,"style":81},"language-go shiki shiki-themes github-light github-dark","package main\n\nimport \"fmt\"\n\ntype UserRepository struct{}\n\nfunc (ur *UserRepository) Save(name string) {\n    fmt.Println(\"Saving user: \", name)\n}\n\nfunc NewUserRepository() *UserRepository {\n    return &UserRepository{}\n}\n\ntype NotifService struct{}\n\nfunc (ns *NotifService) Send(message string) {\n    fmt.Println(message)\n}\n\nfunc NewNotifService() *NotifService {\n    return &NotifService{}\n}\n\ntype SignupService struct {\n}\n\nfunc (s *SignupService) UserSignup() {\n    \u002F\u002Finitialize the repository\n    userRepository := NewUserRepository()\n\n    \u002F\u002Fstore the data\n    userRepository.Save(\"Mohit\")\n\n    \u002F\u002F initialize the notification service\n    notifSvc := NewNotifService()\n\n    \u002F\u002F send welcome notification\n    notifSvc.Send(\"Welcome to Mohit's blog\")\n\n    \u002F\u002F more operation ...\n\n    return\n}\n\nfunc main() {\n    fmt.Println(\"Aim: learning dependency injection\")\n    signupService := SignupService{}\n    signupService.UserSignup()\n}\n","go","",[83,84,85,98,105,121,126,142,147,184,201,207,212,230,243,248,253,265,270,299,309,314,319,335,346,351,356,368,373,378,401,408,422,427,433,449,454,460,472,477,483,498,503,509,514,520,525,530,540,554,566,576],"code",{"__ignoreMap":81},[86,87,90,94],"span",{"class":88,"line":89},"line",1,[86,91,93],{"class":92},"szBVR","package",[86,95,97],{"class":96},"sScJk"," main\n",[86,99,101],{"class":88,"line":100},2,[86,102,104],{"emptyLinePlaceholder":103},true,"\n",[86,106,108,111,115,118],{"class":88,"line":107},3,[86,109,110],{"class":92},"import",[86,112,114],{"class":113},"sZZnC"," \"",[86,116,117],{"class":96},"fmt",[86,119,120],{"class":113},"\"\n",[86,122,124],{"class":88,"line":123},4,[86,125,104],{"emptyLinePlaceholder":103},[86,127,129,132,135,138],{"class":88,"line":128},5,[86,130,131],{"class":92},"type",[86,133,134],{"class":96}," UserRepository",[86,136,137],{"class":92}," struct",[86,139,141],{"class":140},"sVt8B","{}\n",[86,143,145],{"class":88,"line":144},6,[86,146,104],{"emptyLinePlaceholder":103},[86,148,150,153,156,160,163,166,169,172,175,178,181],{"class":88,"line":149},7,[86,151,152],{"class":92},"func",[86,154,155],{"class":140}," (",[86,157,159],{"class":158},"s4XuR","ur ",[86,161,162],{"class":92},"*",[86,164,165],{"class":96},"UserRepository",[86,167,168],{"class":140},") ",[86,170,171],{"class":96},"Save",[86,173,174],{"class":140},"(",[86,176,177],{"class":158},"name",[86,179,180],{"class":92}," string",[86,182,183],{"class":140},") {\n",[86,185,187,190,193,195,198],{"class":88,"line":186},8,[86,188,189],{"class":140},"    fmt.",[86,191,192],{"class":96},"Println",[86,194,174],{"class":140},[86,196,197],{"class":113},"\"Saving user: \"",[86,199,200],{"class":140},", name)\n",[86,202,204],{"class":88,"line":203},9,[86,205,206],{"class":140},"}\n",[86,208,210],{"class":88,"line":209},10,[86,211,104],{"emptyLinePlaceholder":103},[86,213,215,217,220,223,225,227],{"class":88,"line":214},11,[86,216,152],{"class":92},[86,218,219],{"class":96}," NewUserRepository",[86,221,222],{"class":140},"() ",[86,224,162],{"class":92},[86,226,165],{"class":96},[86,228,229],{"class":140}," {\n",[86,231,233,236,239,241],{"class":88,"line":232},12,[86,234,235],{"class":92},"    return",[86,237,238],{"class":92}," &",[86,240,165],{"class":96},[86,242,141],{"class":140},[86,244,246],{"class":88,"line":245},13,[86,247,206],{"class":140},[86,249,251],{"class":88,"line":250},14,[86,252,104],{"emptyLinePlaceholder":103},[86,254,256,258,261,263],{"class":88,"line":255},15,[86,257,131],{"class":92},[86,259,260],{"class":96}," NotifService",[86,262,137],{"class":92},[86,264,141],{"class":140},[86,266,268],{"class":88,"line":267},16,[86,269,104],{"emptyLinePlaceholder":103},[86,271,273,275,277,280,282,285,287,290,292,295,297],{"class":88,"line":272},17,[86,274,152],{"class":92},[86,276,155],{"class":140},[86,278,279],{"class":158},"ns ",[86,281,162],{"class":92},[86,283,284],{"class":96},"NotifService",[86,286,168],{"class":140},[86,288,289],{"class":96},"Send",[86,291,174],{"class":140},[86,293,294],{"class":158},"message",[86,296,180],{"class":92},[86,298,183],{"class":140},[86,300,302,304,306],{"class":88,"line":301},18,[86,303,189],{"class":140},[86,305,192],{"class":96},[86,307,308],{"class":140},"(message)\n",[86,310,312],{"class":88,"line":311},19,[86,313,206],{"class":140},[86,315,317],{"class":88,"line":316},20,[86,318,104],{"emptyLinePlaceholder":103},[86,320,322,324,327,329,331,333],{"class":88,"line":321},21,[86,323,152],{"class":92},[86,325,326],{"class":96}," NewNotifService",[86,328,222],{"class":140},[86,330,162],{"class":92},[86,332,284],{"class":96},[86,334,229],{"class":140},[86,336,338,340,342,344],{"class":88,"line":337},22,[86,339,235],{"class":92},[86,341,238],{"class":92},[86,343,284],{"class":96},[86,345,141],{"class":140},[86,347,349],{"class":88,"line":348},23,[86,350,206],{"class":140},[86,352,354],{"class":88,"line":353},24,[86,355,104],{"emptyLinePlaceholder":103},[86,357,359,361,364,366],{"class":88,"line":358},25,[86,360,131],{"class":92},[86,362,363],{"class":96}," SignupService",[86,365,137],{"class":92},[86,367,229],{"class":140},[86,369,371],{"class":88,"line":370},26,[86,372,206],{"class":140},[86,374,376],{"class":88,"line":375},27,[86,377,104],{"emptyLinePlaceholder":103},[86,379,381,383,385,388,390,393,395,398],{"class":88,"line":380},28,[86,382,152],{"class":92},[86,384,155],{"class":140},[86,386,387],{"class":158},"s ",[86,389,162],{"class":92},[86,391,392],{"class":96},"SignupService",[86,394,168],{"class":140},[86,396,397],{"class":96},"UserSignup",[86,399,400],{"class":140},"() {\n",[86,402,404],{"class":88,"line":403},29,[86,405,407],{"class":406},"sJ8bj","    \u002F\u002Finitialize the repository\n",[86,409,411,414,417,419],{"class":88,"line":410},30,[86,412,413],{"class":140},"    userRepository ",[86,415,416],{"class":92},":=",[86,418,219],{"class":96},[86,420,421],{"class":140},"()\n",[86,423,425],{"class":88,"line":424},31,[86,426,104],{"emptyLinePlaceholder":103},[86,428,430],{"class":88,"line":429},32,[86,431,432],{"class":406},"    \u002F\u002Fstore the data\n",[86,434,436,439,441,443,446],{"class":88,"line":435},33,[86,437,438],{"class":140},"    userRepository.",[86,440,171],{"class":96},[86,442,174],{"class":140},[86,444,445],{"class":113},"\"Mohit\"",[86,447,448],{"class":140},")\n",[86,450,452],{"class":88,"line":451},34,[86,453,104],{"emptyLinePlaceholder":103},[86,455,457],{"class":88,"line":456},35,[86,458,459],{"class":406},"    \u002F\u002F initialize the notification service\n",[86,461,463,466,468,470],{"class":88,"line":462},36,[86,464,465],{"class":140},"    notifSvc ",[86,467,416],{"class":92},[86,469,326],{"class":96},[86,471,421],{"class":140},[86,473,475],{"class":88,"line":474},37,[86,476,104],{"emptyLinePlaceholder":103},[86,478,480],{"class":88,"line":479},38,[86,481,482],{"class":406},"    \u002F\u002F send welcome notification\n",[86,484,486,489,491,493,496],{"class":88,"line":485},39,[86,487,488],{"class":140},"    notifSvc.",[86,490,289],{"class":96},[86,492,174],{"class":140},[86,494,495],{"class":113},"\"Welcome to Mohit's blog\"",[86,497,448],{"class":140},[86,499,501],{"class":88,"line":500},40,[86,502,104],{"emptyLinePlaceholder":103},[86,504,506],{"class":88,"line":505},41,[86,507,508],{"class":406},"    \u002F\u002F more operation ...\n",[86,510,512],{"class":88,"line":511},42,[86,513,104],{"emptyLinePlaceholder":103},[86,515,517],{"class":88,"line":516},43,[86,518,519],{"class":92},"    return\n",[86,521,523],{"class":88,"line":522},44,[86,524,206],{"class":140},[86,526,528],{"class":88,"line":527},45,[86,529,104],{"emptyLinePlaceholder":103},[86,531,533,535,538],{"class":88,"line":532},46,[86,534,152],{"class":92},[86,536,537],{"class":96}," main",[86,539,400],{"class":140},[86,541,543,545,547,549,552],{"class":88,"line":542},47,[86,544,189],{"class":140},[86,546,192],{"class":96},[86,548,174],{"class":140},[86,550,551],{"class":113},"\"Aim: learning dependency injection\"",[86,553,448],{"class":140},[86,555,557,560,562,564],{"class":88,"line":556},48,[86,558,559],{"class":140},"    signupService ",[86,561,416],{"class":92},[86,563,363],{"class":96},[86,565,141],{"class":140},[86,567,569,572,574],{"class":88,"line":568},49,[86,570,571],{"class":140},"    signupService.",[86,573,397],{"class":96},[86,575,421],{"class":140},[86,577,579],{"class":88,"line":578},50,[86,580,206],{"class":140},[11,582,583,584,586],{},"Here we are creating a user signup service where we create dependencies of repository and notifications and execute operations that are expected on user signup. The issue here is you're creating objects for each dependency whenever a signup method is called. You cannot change notification from say mobile push notification to a whatsapp notification without modifying the ",[83,585,397],{}," function.",[65,588],{},[590,591,593],"h3",{"id":592},"one-step-forward","One step forward",[11,595,596],{},"Let's update our code so that we don't create new objects on each user signup call. That's bad right?",[76,598,600],{"className":78,"code":599,"language":80,"meta":81,"style":81},"package main\n\nimport \"fmt\"\n\ntype UserRepository struct{}\n\nfunc (ur *UserRepository) Save(name string) {\n    fmt.Println(\"Saving user: \", name)\n}\n\nfunc NewUserRepository() *UserRepository {\n    return &UserRepository{}\n}\n\ntype NotifService struct{}\n\nfunc (ns *NotifService) Send(message string) {\n    fmt.Println(message)\n}\n\nfunc NewNotifService() *NotifService {\n    return &NotifService{}\n}\n\ntype SignupService struct {\n    userRepository *UserRepository\n    notifSvc       *NotifService\n}\n\nfunc NewSignupService(userRepository *UserRepository, notifSvc *NotifService) *SignupService {\n    return &SignupService{\n        userRepository: userRepository,\n        notifSvc:       notifSvc,\n    }\n}\n\nfunc (s *SignupService) UserSignup() {\n  \u002F\u002F notice no initialization of dependencies required here.\n  \n    \u002F\u002Fstore the data\n    s.userRepository.Save(\"Mohit\")\n\n    \u002F\u002F send welcome notification\n    s.notifSvc.Send(\"Welcome to Mohit's blog\")\n\n    \u002F\u002F more operation ...\n    return\n}\n\nfunc main() {\n    fmt.Println(\"Aim: learning dependency injection\")\n\n    \u002F\u002F initialize once\n    userRepository := NewUserRepository()\n    notifSvc := NewNotifService()\n    signupService := NewSignupService(userRepository, notifSvc)\n\n    \u002F\u002F use the methods\n    signupService.UserSignup()\n}\n",[83,601,602,608,612,622,626,636,640,664,676,680,684,698,708,712,716,726,730,754,762,766,770,784,794,798,802,812,821,831,835,839,874,885,890,895,900,904,908,926,931,936,940,953,957,961,974,978,982,986,990,994,1002,1015,1020,1026,1037,1048,1060,1065,1071,1080],{"__ignoreMap":81},[86,603,604,606],{"class":88,"line":89},[86,605,93],{"class":92},[86,607,97],{"class":96},[86,609,610],{"class":88,"line":100},[86,611,104],{"emptyLinePlaceholder":103},[86,613,614,616,618,620],{"class":88,"line":107},[86,615,110],{"class":92},[86,617,114],{"class":113},[86,619,117],{"class":96},[86,621,120],{"class":113},[86,623,624],{"class":88,"line":123},[86,625,104],{"emptyLinePlaceholder":103},[86,627,628,630,632,634],{"class":88,"line":128},[86,629,131],{"class":92},[86,631,134],{"class":96},[86,633,137],{"class":92},[86,635,141],{"class":140},[86,637,638],{"class":88,"line":144},[86,639,104],{"emptyLinePlaceholder":103},[86,641,642,644,646,648,650,652,654,656,658,660,662],{"class":88,"line":149},[86,643,152],{"class":92},[86,645,155],{"class":140},[86,647,159],{"class":158},[86,649,162],{"class":92},[86,651,165],{"class":96},[86,653,168],{"class":140},[86,655,171],{"class":96},[86,657,174],{"class":140},[86,659,177],{"class":158},[86,661,180],{"class":92},[86,663,183],{"class":140},[86,665,666,668,670,672,674],{"class":88,"line":186},[86,667,189],{"class":140},[86,669,192],{"class":96},[86,671,174],{"class":140},[86,673,197],{"class":113},[86,675,200],{"class":140},[86,677,678],{"class":88,"line":203},[86,679,206],{"class":140},[86,681,682],{"class":88,"line":209},[86,683,104],{"emptyLinePlaceholder":103},[86,685,686,688,690,692,694,696],{"class":88,"line":214},[86,687,152],{"class":92},[86,689,219],{"class":96},[86,691,222],{"class":140},[86,693,162],{"class":92},[86,695,165],{"class":96},[86,697,229],{"class":140},[86,699,700,702,704,706],{"class":88,"line":232},[86,701,235],{"class":92},[86,703,238],{"class":92},[86,705,165],{"class":96},[86,707,141],{"class":140},[86,709,710],{"class":88,"line":245},[86,711,206],{"class":140},[86,713,714],{"class":88,"line":250},[86,715,104],{"emptyLinePlaceholder":103},[86,717,718,720,722,724],{"class":88,"line":255},[86,719,131],{"class":92},[86,721,260],{"class":96},[86,723,137],{"class":92},[86,725,141],{"class":140},[86,727,728],{"class":88,"line":267},[86,729,104],{"emptyLinePlaceholder":103},[86,731,732,734,736,738,740,742,744,746,748,750,752],{"class":88,"line":272},[86,733,152],{"class":92},[86,735,155],{"class":140},[86,737,279],{"class":158},[86,739,162],{"class":92},[86,741,284],{"class":96},[86,743,168],{"class":140},[86,745,289],{"class":96},[86,747,174],{"class":140},[86,749,294],{"class":158},[86,751,180],{"class":92},[86,753,183],{"class":140},[86,755,756,758,760],{"class":88,"line":301},[86,757,189],{"class":140},[86,759,192],{"class":96},[86,761,308],{"class":140},[86,763,764],{"class":88,"line":311},[86,765,206],{"class":140},[86,767,768],{"class":88,"line":316},[86,769,104],{"emptyLinePlaceholder":103},[86,771,772,774,776,778,780,782],{"class":88,"line":321},[86,773,152],{"class":92},[86,775,326],{"class":96},[86,777,222],{"class":140},[86,779,162],{"class":92},[86,781,284],{"class":96},[86,783,229],{"class":140},[86,785,786,788,790,792],{"class":88,"line":337},[86,787,235],{"class":92},[86,789,238],{"class":92},[86,791,284],{"class":96},[86,793,141],{"class":140},[86,795,796],{"class":88,"line":348},[86,797,206],{"class":140},[86,799,800],{"class":88,"line":353},[86,801,104],{"emptyLinePlaceholder":103},[86,803,804,806,808,810],{"class":88,"line":358},[86,805,131],{"class":92},[86,807,363],{"class":96},[86,809,137],{"class":92},[86,811,229],{"class":140},[86,813,814,816,818],{"class":88,"line":370},[86,815,413],{"class":140},[86,817,162],{"class":92},[86,819,820],{"class":96},"UserRepository\n",[86,822,823,826,828],{"class":88,"line":375},[86,824,825],{"class":140},"    notifSvc       ",[86,827,162],{"class":92},[86,829,830],{"class":96},"NotifService\n",[86,832,833],{"class":88,"line":380},[86,834,206],{"class":140},[86,836,837],{"class":88,"line":403},[86,838,104],{"emptyLinePlaceholder":103},[86,840,841,843,846,848,851,854,856,859,862,864,866,868,870,872],{"class":88,"line":410},[86,842,152],{"class":92},[86,844,845],{"class":96}," NewSignupService",[86,847,174],{"class":140},[86,849,850],{"class":158},"userRepository",[86,852,853],{"class":92}," *",[86,855,165],{"class":96},[86,857,858],{"class":140},", ",[86,860,861],{"class":158},"notifSvc",[86,863,853],{"class":92},[86,865,284],{"class":96},[86,867,168],{"class":140},[86,869,162],{"class":92},[86,871,392],{"class":96},[86,873,229],{"class":140},[86,875,876,878,880,882],{"class":88,"line":424},[86,877,235],{"class":92},[86,879,238],{"class":92},[86,881,392],{"class":96},[86,883,884],{"class":140},"{\n",[86,886,887],{"class":88,"line":429},[86,888,889],{"class":140},"        userRepository: userRepository,\n",[86,891,892],{"class":88,"line":435},[86,893,894],{"class":140},"        notifSvc:       notifSvc,\n",[86,896,897],{"class":88,"line":451},[86,898,899],{"class":140},"    }\n",[86,901,902],{"class":88,"line":456},[86,903,206],{"class":140},[86,905,906],{"class":88,"line":462},[86,907,104],{"emptyLinePlaceholder":103},[86,909,910,912,914,916,918,920,922,924],{"class":88,"line":474},[86,911,152],{"class":92},[86,913,155],{"class":140},[86,915,387],{"class":158},[86,917,162],{"class":92},[86,919,392],{"class":96},[86,921,168],{"class":140},[86,923,397],{"class":96},[86,925,400],{"class":140},[86,927,928],{"class":88,"line":479},[86,929,930],{"class":406},"  \u002F\u002F notice no initialization of dependencies required here.\n",[86,932,933],{"class":88,"line":485},[86,934,935],{"class":140},"  \n",[86,937,938],{"class":88,"line":500},[86,939,432],{"class":406},[86,941,942,945,947,949,951],{"class":88,"line":505},[86,943,944],{"class":140},"    s.userRepository.",[86,946,171],{"class":96},[86,948,174],{"class":140},[86,950,445],{"class":113},[86,952,448],{"class":140},[86,954,955],{"class":88,"line":511},[86,956,104],{"emptyLinePlaceholder":103},[86,958,959],{"class":88,"line":516},[86,960,482],{"class":406},[86,962,963,966,968,970,972],{"class":88,"line":522},[86,964,965],{"class":140},"    s.notifSvc.",[86,967,289],{"class":96},[86,969,174],{"class":140},[86,971,495],{"class":113},[86,973,448],{"class":140},[86,975,976],{"class":88,"line":527},[86,977,104],{"emptyLinePlaceholder":103},[86,979,980],{"class":88,"line":532},[86,981,508],{"class":406},[86,983,984],{"class":88,"line":542},[86,985,519],{"class":92},[86,987,988],{"class":88,"line":556},[86,989,206],{"class":140},[86,991,992],{"class":88,"line":568},[86,993,104],{"emptyLinePlaceholder":103},[86,995,996,998,1000],{"class":88,"line":578},[86,997,152],{"class":92},[86,999,537],{"class":96},[86,1001,400],{"class":140},[86,1003,1005,1007,1009,1011,1013],{"class":88,"line":1004},51,[86,1006,189],{"class":140},[86,1008,192],{"class":96},[86,1010,174],{"class":140},[86,1012,551],{"class":113},[86,1014,448],{"class":140},[86,1016,1018],{"class":88,"line":1017},52,[86,1019,104],{"emptyLinePlaceholder":103},[86,1021,1023],{"class":88,"line":1022},53,[86,1024,1025],{"class":406},"    \u002F\u002F initialize once\n",[86,1027,1029,1031,1033,1035],{"class":88,"line":1028},54,[86,1030,413],{"class":140},[86,1032,416],{"class":92},[86,1034,219],{"class":96},[86,1036,421],{"class":140},[86,1038,1040,1042,1044,1046],{"class":88,"line":1039},55,[86,1041,465],{"class":140},[86,1043,416],{"class":92},[86,1045,326],{"class":96},[86,1047,421],{"class":140},[86,1049,1051,1053,1055,1057],{"class":88,"line":1050},56,[86,1052,559],{"class":140},[86,1054,416],{"class":92},[86,1056,845],{"class":96},[86,1058,1059],{"class":140},"(userRepository, notifSvc)\n",[86,1061,1063],{"class":88,"line":1062},57,[86,1064,104],{"emptyLinePlaceholder":103},[86,1066,1068],{"class":88,"line":1067},58,[86,1069,1070],{"class":406},"    \u002F\u002F use the methods\n",[86,1072,1074,1076,1078],{"class":88,"line":1073},59,[86,1075,571],{"class":140},[86,1077,397],{"class":96},[86,1079,421],{"class":140},[86,1081,1083],{"class":88,"line":1082},60,[86,1084,206],{"class":140},[11,1086,1087,1088,1091],{},"The major benefit we get here is that we can ",[15,1089,1090],{},"explicitly choose when to create new instances"," of our dependencies vs when to reuse the same instance. I could create a new instance with whatsapp notification implementation (assume we add interface) instead of using current implementation.",[65,1093],{},[590,1095,1097],{"id":1096},"make-it-better-with-di-containers","Make it better with DI Containers",[11,1099,1100],{},"Ok so we solved problem of creating vs using dependency. I'll leave using interface in above code as an exercise for you folks. The next problem which comes as your code complexity grows is maintaining dependencies. At my workplace CRED, in of key services where we manage bill payments we have over 10 dependencies at places. Imagine managing such dependencies at multiple places.  Trust me, it's real pain!",[11,1102,1103,1104,1107,1108,1111,1112,1119,1120,1122],{},"This is where a ",[15,1105,1106],{},"Dependency injection container","  comes in allowing us to automatically update dependencies without defining it manually in our code. We'll use an open source package called ",[83,1109,1110],{},"wire"," . This package is maintained by the google team. There are lot of other popular ",[30,1113,1116],{"href":1114,"rel":1115},"https:\u002F\u002Fgithub.com\u002Fuber-go\u002Fdig",[34],[83,1117,1118],{},"uber-go\u002Fdig"," and many more that you can use as well. For this example we'll use ",[83,1121,1110],{},".",[11,1124,1125,1126,1129],{},"Let's add ",[83,1127,1128],{},"wire.go"," file.",[76,1131,1133],{"className":78,"code":1132,"language":80,"meta":81,"style":81},"\u002F\u002Fgo:build wireinject\n\npackage main\n\nimport \"github.com\u002Fgoogle\u002Fwire\"\n\nfunc Initialize() *SignupService {\n    panic(wire.Build(\n        NewSignupService,\n        NewUserRepository,\n        NewNotifService,\n    ))\n}\n",[83,1134,1135,1140,1144,1150,1154,1165,1169,1184,1198,1203,1208,1213,1218],{"__ignoreMap":81},[86,1136,1137],{"class":88,"line":89},[86,1138,1139],{"class":406},"\u002F\u002Fgo:build wireinject\n",[86,1141,1142],{"class":88,"line":100},[86,1143,104],{"emptyLinePlaceholder":103},[86,1145,1146,1148],{"class":88,"line":107},[86,1147,93],{"class":92},[86,1149,97],{"class":96},[86,1151,1152],{"class":88,"line":123},[86,1153,104],{"emptyLinePlaceholder":103},[86,1155,1156,1158,1160,1163],{"class":88,"line":128},[86,1157,110],{"class":92},[86,1159,114],{"class":113},[86,1161,1162],{"class":96},"github.com\u002Fgoogle\u002Fwire",[86,1164,120],{"class":113},[86,1166,1167],{"class":88,"line":144},[86,1168,104],{"emptyLinePlaceholder":103},[86,1170,1171,1173,1176,1178,1180,1182],{"class":88,"line":149},[86,1172,152],{"class":92},[86,1174,1175],{"class":96}," Initialize",[86,1177,222],{"class":140},[86,1179,162],{"class":92},[86,1181,392],{"class":96},[86,1183,229],{"class":140},[86,1185,1186,1189,1192,1195],{"class":88,"line":186},[86,1187,1188],{"class":96},"    panic",[86,1190,1191],{"class":140},"(wire.",[86,1193,1194],{"class":96},"Build",[86,1196,1197],{"class":140},"(\n",[86,1199,1200],{"class":88,"line":203},[86,1201,1202],{"class":140},"        NewSignupService,\n",[86,1204,1205],{"class":88,"line":209},[86,1206,1207],{"class":140},"        NewUserRepository,\n",[86,1209,1210],{"class":88,"line":214},[86,1211,1212],{"class":140},"        NewNotifService,\n",[86,1214,1215],{"class":88,"line":232},[86,1216,1217],{"class":140},"    ))\n",[86,1219,1220],{"class":88,"line":245},[86,1221,206],{"class":140},[11,1223,1224,1225,1228],{},"We now need to use this ",[83,1226,1227],{},"Initialize"," method in our main function.",[76,1230,1232],{"className":78,"code":1231,"language":80,"meta":81,"style":81},"package main\n\nimport (\n    \"github.com\u002Fgoogle\u002Fwire\"\n)\n\n\u002F\u002F old code from before\n\u002F\u002F ...\n\nfunc main() {\n    fmt.Println(\"Aim: learning dependency injection\")\n    userSignupSvc := Initialize()\n    userSignupSvc.UserSignup()\n}\n",[83,1233,1234,1240,1244,1251,1260,1264,1268,1273,1278,1282,1290,1302,1313,1322],{"__ignoreMap":81},[86,1235,1236,1238],{"class":88,"line":89},[86,1237,93],{"class":92},[86,1239,97],{"class":96},[86,1241,1242],{"class":88,"line":100},[86,1243,104],{"emptyLinePlaceholder":103},[86,1245,1246,1248],{"class":88,"line":107},[86,1247,110],{"class":92},[86,1249,1250],{"class":140}," (\n",[86,1252,1253,1256,1258],{"class":88,"line":123},[86,1254,1255],{"class":113},"    \"",[86,1257,1162],{"class":96},[86,1259,120],{"class":113},[86,1261,1262],{"class":88,"line":128},[86,1263,448],{"class":140},[86,1265,1266],{"class":88,"line":144},[86,1267,104],{"emptyLinePlaceholder":103},[86,1269,1270],{"class":88,"line":149},[86,1271,1272],{"class":406},"\u002F\u002F old code from before\n",[86,1274,1275],{"class":88,"line":186},[86,1276,1277],{"class":406},"\u002F\u002F ...\n",[86,1279,1280],{"class":88,"line":203},[86,1281,104],{"emptyLinePlaceholder":103},[86,1283,1284,1286,1288],{"class":88,"line":209},[86,1285,152],{"class":92},[86,1287,537],{"class":96},[86,1289,400],{"class":140},[86,1291,1292,1294,1296,1298,1300],{"class":88,"line":214},[86,1293,189],{"class":140},[86,1295,192],{"class":96},[86,1297,174],{"class":140},[86,1299,551],{"class":113},[86,1301,448],{"class":140},[86,1303,1304,1307,1309,1311],{"class":88,"line":232},[86,1305,1306],{"class":140},"    userSignupSvc ",[86,1308,416],{"class":92},[86,1310,1175],{"class":96},[86,1312,421],{"class":140},[86,1314,1315,1318,1320],{"class":88,"line":245},[86,1316,1317],{"class":140},"    userSignupSvc.",[86,1319,397],{"class":96},[86,1321,421],{"class":140},[86,1323,1324],{"class":88,"line":250},[86,1325,206],{"class":140},[1327,1328,1329,1336],"ol",{},[1330,1331,1332,1333,1335],"li",{},"To tell go that wiring should happen only when ",[83,1334,1110],{}," is building and not in other workflows we add buildTag.",[1330,1337,1338,1339,1342,1343,1346],{},"We’ve replaced the creation of userRepository and notifService with a ",[83,1340,1341],{},"Initialize()"," call .  Inside this function we pass all of the constructors in our application to ",[83,1344,1345],{},"wire.Build",". These arguments can be functions and structs.",[11,1348,1349,1350,1352],{},"To see this working, let's quickly install the ",[83,1351,1110],{}," package",[76,1354,1358],{"className":1355,"code":1356,"language":1357,"meta":81,"style":81},"language-bash shiki shiki-themes github-light github-dark","go install github.com\u002Fgoogle\u002Fwire\u002Fcmd\u002Fwire@latest\n\n# now run wire command\nwire\n","bash",[83,1359,1360,1370,1374,1379],{"__ignoreMap":81},[86,1361,1362,1364,1367],{"class":88,"line":89},[86,1363,80],{"class":96},[86,1365,1366],{"class":113}," install",[86,1368,1369],{"class":113}," github.com\u002Fgoogle\u002Fwire\u002Fcmd\u002Fwire@latest\n",[86,1371,1372],{"class":88,"line":100},[86,1373,104],{"emptyLinePlaceholder":103},[86,1375,1376],{"class":88,"line":107},[86,1377,1378],{"class":406},"# now run wire command\n",[86,1380,1381],{"class":88,"line":123},[86,1382,1383],{"class":96},"wire\n",[11,1385,1386,1387,1129],{},"This creates ",[83,1388,1389],{},"wire_gen.go",[76,1391,1393],{"className":78,"code":1392,"language":80,"meta":81,"style":81},"\u002F\u002F Code generated by Wire. DO NOT EDIT.\n\n\u002F\u002Fgo:generate go run github.com\u002Fgoogle\u002Fwire\u002Fcmd\u002Fwire\n\u002F\u002Fgo:build !wireinject\n\u002F\u002F +build !wireinject\n\npackage main\n\n\u002F\u002F Injectors from wire.go:\n\nfunc Initialize() *SignupService {\n    userRepository := NewUserRepository()\n    notifService := NewNotifService()\n    signupService := NewSignupService(userRepository, notifService)\n    return signupService\n}\n",[83,1394,1395,1400,1404,1409,1414,1419,1423,1429,1433,1438,1442,1456,1466,1477,1488,1495],{"__ignoreMap":81},[86,1396,1397],{"class":88,"line":89},[86,1398,1399],{"class":406},"\u002F\u002F Code generated by Wire. DO NOT EDIT.\n",[86,1401,1402],{"class":88,"line":100},[86,1403,104],{"emptyLinePlaceholder":103},[86,1405,1406],{"class":88,"line":107},[86,1407,1408],{"class":406},"\u002F\u002Fgo:generate go run github.com\u002Fgoogle\u002Fwire\u002Fcmd\u002Fwire\n",[86,1410,1411],{"class":88,"line":123},[86,1412,1413],{"class":406},"\u002F\u002Fgo:build !wireinject\n",[86,1415,1416],{"class":88,"line":128},[86,1417,1418],{"class":406},"\u002F\u002F +build !wireinject\n",[86,1420,1421],{"class":88,"line":144},[86,1422,104],{"emptyLinePlaceholder":103},[86,1424,1425,1427],{"class":88,"line":149},[86,1426,93],{"class":92},[86,1428,97],{"class":96},[86,1430,1431],{"class":88,"line":186},[86,1432,104],{"emptyLinePlaceholder":103},[86,1434,1435],{"class":88,"line":203},[86,1436,1437],{"class":406},"\u002F\u002F Injectors from wire.go:\n",[86,1439,1440],{"class":88,"line":209},[86,1441,104],{"emptyLinePlaceholder":103},[86,1443,1444,1446,1448,1450,1452,1454],{"class":88,"line":214},[86,1445,152],{"class":92},[86,1447,1175],{"class":96},[86,1449,222],{"class":140},[86,1451,162],{"class":92},[86,1453,392],{"class":96},[86,1455,229],{"class":140},[86,1457,1458,1460,1462,1464],{"class":88,"line":232},[86,1459,413],{"class":140},[86,1461,416],{"class":92},[86,1463,219],{"class":96},[86,1465,421],{"class":140},[86,1467,1468,1471,1473,1475],{"class":88,"line":245},[86,1469,1470],{"class":140},"    notifService ",[86,1472,416],{"class":92},[86,1474,326],{"class":96},[86,1476,421],{"class":140},[86,1478,1479,1481,1483,1485],{"class":88,"line":250},[86,1480,559],{"class":140},[86,1482,416],{"class":92},[86,1484,845],{"class":96},[86,1486,1487],{"class":140},"(userRepository, notifService)\n",[86,1489,1490,1492],{"class":88,"line":255},[86,1491,235],{"class":92},[86,1493,1494],{"class":140}," signupService\n",[86,1496,1497],{"class":88,"line":267},[86,1498,206],{"class":140},[11,1500,1501,1504],{},[15,1502,1503],{},"Boom!"," Wire automatically generates the code we manually wrote before. Imagine how much manual code you would save in complex codebases.",[11,1506,1507,1508,1510,1511,1514,1515,1518,1519,1522],{},"Also to add in ",[83,1509,1389],{}," you can see the ",[83,1512,1513],{},"go:generate"," comment. If you're not aware about ",[83,1516,1517],{},"go generate"," - it helps in automating running tools to generate source code before compilation. So for this case, you could simply run ",[83,1520,1521],{},"go generate .\u002F..."," and files would be regenerated by wire.",[65,1524],{},[68,1526,1528],{"id":1527},"how-does-wire-work","How does wire work?",[11,1530,1531,1532,1534],{},"You saw how ",[83,1533,1389],{}," was created the code. How did wire know about what functions to add?",[11,1536,1537,1538,1540,1541,1544,1545,1547],{},"Wire basically relies on code generation and reflection to analyze the source code and produce injection code. So ",[83,1539,1110],{}," command looks for files tagged with the ",[83,1542,1543],{},"\u002F\u002F+build wireinject"," build constraint. Once it knows about these files, it looks inside them for any function that had a call to ",[83,1546,1345],{},". Finally, it looks at all the arguments and return type of that function. It creates code based on arguments and return type of each function and passes this information to wire where it's used as input to the dependency graph.",[11,1549,1550,1551,1555],{},"For more curious one's wire relies on code generation and not reflection like other similar packages.You can also see how topological sort (also DFS: depth first search) is used to build a dependency graph internally in the ",[30,1552,83],{"href":1553,"rel":1554},"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fwire\u002Fblob\u002F0ac845078ca01a1755571c53d7a8e7995b96e40d\u002Finternal\u002Fwire\u002Fanalyze.go#L95",[34],". See those graph algorithms are actually used 😛",[11,1557,1558,1559,1561,1562,1122],{},"There are more functions provided by ",[83,1560,1110],{}," you can read more on the ",[30,1563,1566],{"href":1564,"rel":1565},"https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgoogle\u002Fwire#section-readme",[34],"go blog",[65,1568],{},[68,1570,1572],{"id":1571},"resources","Resources",[1574,1575,1576,1583],"ul",{},[1330,1577,1578],{},[30,1579,1582],{"href":1580,"rel":1581},"https:\u002F\u002Fgo.dev\u002Fblog\u002Fwire",[34],"Overview to wire",[1330,1584,1585],{},[30,1586,1589],{"href":1587,"rel":1588},"https:\u002F\u002Fmedium.com\u002Favenue-tech\u002Fdependency-injection-in-go-35293ef7b6",[34],"Dependency graph graphics in DI explanation",[590,1591,1593],{"id":1592},"books-to-learn-golang","Books to learn Golang",[1574,1595,1596,1603,1610],{},[1330,1597,1598],{},[30,1599,1602],{"href":1600,"rel":1601},"https:\u002F\u002Famzn.to\u002F3fYLCqz",[34],"Go Programming Language",[1330,1604,1605],{},[30,1606,1609],{"href":1607,"rel":1608},"https:\u002F\u002Famzn.to\u002F3s7fWS3",[34],"Learning Go",[1330,1611,1612],{},[30,1613,1616],{"href":1614,"rel":1615},"https:\u002F\u002Famzn.to\u002F3t6PM37",[34],"Go in Action",[11,1618,1619,1620,1625],{},"Liked the article? Consider ",[30,1621,1624],{"href":1622,"rel":1623},"https:\u002F\u002Fwww.buymeacoffee.com\u002FchHAzigTb",[34],"supporting me"," ☕️",[65,1627],{},[11,1629,1630],{},"I hope you learned something new. Feel free to suggest improvements ✔️",[11,1632,1633,1634,1639],{},"Follow me on ",[30,1635,1638],{"href":1636,"rel":1637},"https:\u002F\u002Ftwitter.com\u002Fmkfeuhrer",[34],"Twitter"," for updates and resources. Let's connect!",[11,1641,1642],{},[15,1643,1644],{},"Keep exploring 🔎 Keep learning 🚀",[1646,1647,1648],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}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 .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}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}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);}",{"title":81,"searchDepth":100,"depth":100,"links":1650},[1651,1655,1656],{"id":70,"depth":100,"text":71,"children":1652},[1653,1654],{"id":592,"depth":107,"text":593},{"id":1096,"depth":107,"text":1097},{"id":1527,"depth":100,"text":1528},{"id":1571,"depth":100,"text":1572,"children":1657},[1658],{"id":1592,"depth":107,"text":1593},[53,1660],"Programming","Learn about dependency injection, its benefits and how to implement it in Go services using wire",false,"md","blog\u002Fgo-dependency-injection\u002Fgo-dependency-injection-card.webp","golang wire dependency injection, golang wire tutorial, go dependency injection framework",{},"go-dependency-injection","\u002Fblog\u002Fgo-dependency-injection",{"title":5,"description":1661},"blog\u002Fgo-dependency-injection","2022-11-26","_WPBpJ0FtqGofsPca16yl-cMAa_M34F2K6XbH3YfrV0",[1674,1681,1687,1695,1704,1710,1717,1724,1730,1736,1742,1748,1754,1764,1770,1777,1784,1791,1797,1804,1810,1816,1822,1824,1830,1836,1842,1848,1855,1862,1868,1874,1880,1886,1892,1898,1904,1910,1916,1922,1928,1934,1940,1947,1953,1959,1965,1972,1978,1984,1991,1998,2004,2011,2017,2024,2030,2037,2043,2049,2055,2061,2067,2073,2079,2085,2091,2097,2103,2109,2116,2122,2129,2135,2141,2147,2154,2160],{"path":1675,"title":1676,"description":1677,"categories":1678,"draft":103,"year":1680,"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.",[1679,1660],"Productivity","2026-08-26",{"path":1682,"title":1683,"description":1684,"categories":1685,"draft":1662,"year":1686,"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",[53,1660],"2020-01-12",{"path":1688,"title":1689,"description":1690,"categories":1691,"draft":1662,"year":1694,"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.",[1692,1693],"Books","Life","2021-12-26",{"path":1696,"title":1697,"description":1698,"categories":1699,"draft":1662,"year":1703,"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.",[1700,1701,1702],"Side Projects","Web","Tools","2020-05-26",{"path":1705,"title":1706,"description":1707,"categories":1708,"draft":1662,"year":1709,"series":6},"\u002Fblog\u002Fcap-theorem","CAP Theorem Explained","Learn the concept and misconceptions around popular CAP theorem in system design.",[59,1660],"2021-07-26",{"path":1711,"title":1712,"description":1713,"categories":1714,"draft":1662,"year":1716,"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.",[1715],"Engineering Principles","2020-07-20",{"path":1718,"title":1719,"description":1720,"categories":1721,"draft":1662,"year":1723,"series":6},"\u002Fblog\u002Fdark-mode","Add Dark mode to websites","Dark mode is ❤️️ Add it to your websites with little CSS and JS",[1722,1701],"Javascript","2020-07-04",{"path":1725,"title":1726,"description":1727,"categories":1728,"draft":1662,"year":1729,"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.",[53,1660],"2020-10-09",{"path":1731,"title":1732,"description":1733,"categories":1734,"draft":1662,"year":1735,"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.",[53,1660],"2021-05-05",{"path":1737,"title":1738,"description":1739,"categories":1740,"draft":1662,"year":1741,"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.",[53,1660],"2021-12-18",{"path":1743,"title":1744,"description":1745,"categories":1746,"draft":1662,"year":1747,"series":6},"\u002Fblog\u002Fenvironment-variable-golang","Guide to Environment variables in Go","Learn what are environment variables and how to use them in Go",[53,1660],"2020-08-14",{"path":1749,"title":1750,"description":1751,"categories":1752,"draft":1662,"year":1753,"series":6},"\u002Fblog\u002Ferror-handling-golang","Handle errors the right way — Golang","How to handle errors in golang to make your life easy",[53,1660],"2020-01-30",{"path":1755,"title":1756,"description":1757,"categories":1758,"draft":103,"year":1761,"series":1762},"\u002Fblog\u002Ffile-attack-document-macros","File Attack Deep Dives, Part 3: Document Macros","How malicious VBA hides in vbaProject.bin, which AutoOpen entry points fire it, and the sandbox signals that catch it.",[1759,1760],"Security","Systems","2026-09-17",{"name":1763,"part":107},"File Attack Deep Dives",{"path":1765,"title":1766,"description":1767,"categories":1768,"draft":1662,"year":1680,"series":1769},"\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.",[1759,1760],{"name":1763,"part":89},{"path":1771,"title":1772,"description":1773,"categories":1774,"draft":103,"year":1775,"series":1776},"\u002Fblog\u002Ffile-attack-html-smuggling","File Attack Deep Dives, Part 2: HTML Smuggling","How attackers assemble malware inside the browser with Blob URLs, and the URL and script tells that catch it.",[1759,1760],"2026-09-10",{"name":1763,"part":100},{"path":1778,"title":1779,"description":1780,"categories":1781,"draft":103,"year":1782,"series":1783},"\u002Fblog\u002Ffile-attack-lnk-iso","File Attack Deep Dives, Part 5: LNK and ISO Smuggling","How ISO containers and weaponized shortcuts bypass Mark of the Web, and the forensic fields that catch them.",[1759,1760],"2026-10-01",{"name":1763,"part":128},{"path":1785,"title":1786,"description":1787,"categories":1788,"draft":103,"year":1789,"series":1790},"\u002Fblog\u002Ffile-attack-pdf-url-actions","File Attack Deep Dives, Part 4: PDF URL Actions","How PDF OpenAction, Launch, and URI actions turn opening a document into a phishing click, and the action audit that catches them.",[1759,1760],"2026-09-24",{"name":1763,"part":123},{"path":1792,"title":1793,"description":1794,"categories":1795,"draft":1662,"year":1796,"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.",[53,1660],"2021-03-13",{"path":1798,"title":1799,"description":1800,"categories":1801,"draft":1662,"year":1803,"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.",[1802,1660],"Git","2022-03-20",{"path":1805,"title":1806,"description":1807,"categories":1808,"draft":1662,"year":1809,"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",[1802,1660],"2023-08-24",{"path":1811,"title":1812,"description":1813,"categories":1814,"draft":1662,"year":1815,"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.",[1802,1660],"2023-10-16",{"path":1817,"title":1818,"description":1819,"categories":1820,"draft":1662,"year":1821,"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.",[1802,1660],"2020-06-18",{"path":1668,"title":5,"description":1661,"categories":1823,"draft":1662,"year":1671,"series":6},[53,1660],{"path":1825,"title":1826,"description":1827,"categories":1828,"draft":1662,"year":1829,"series":6},"\u002Fblog\u002Fgo-generics","Introduction to Generics in Go","Learn about generics in Golang, it's benefits and how to implement it in applications.",[53,1660],"2022-11-27",{"path":1831,"title":1832,"description":1833,"categories":1834,"draft":1662,"year":1835,"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).",[53,1660],"2024-03-28",{"path":1837,"title":1838,"description":1839,"categories":1840,"draft":1662,"year":1841,"series":6},"\u002Fblog\u002Fgo-makefile","Ultimate Makefile for Golang","Boost your productivity and save time with ultimate Makefile for Golang projects.",[53,1660],"2024-06-10",{"path":1843,"title":1844,"description":1845,"categories":1846,"draft":1662,"year":1847,"series":6},"\u002Fblog\u002Fgo-middleware","Mastering Middlewares in Golang","Learn about middlewares, their use cases and how to implement them in Golang applications",[53,1660],"2022-03-13",{"path":1849,"title":1850,"description":1851,"categories":1852,"draft":1662,"year":1854,"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.",[53,1660,1853],"Code Quality","2023-05-19",{"path":1856,"title":1857,"description":1858,"categories":1859,"draft":1662,"year":1861,"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.",[53,1860,1660],"Database","2020-05-03",{"path":1863,"title":1864,"description":1865,"categories":1866,"draft":1662,"year":1867,"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.",[53,1660],"2020-09-10",{"path":1869,"title":1870,"description":1871,"categories":1872,"draft":1662,"year":1873,"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.",[59,1660],"2022-01-23",{"path":1875,"title":1876,"description":1877,"categories":1878,"draft":1662,"year":1879,"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",[53,1660],"2022-09-12",{"path":1881,"title":1882,"description":1883,"categories":1884,"draft":1662,"year":1885,"series":6},"\u002Fblog\u002Fhexagonal-architecture","Guide to Hexagonal Architecture","Learn how to design efficient application with hexagonal architecture with practical example",[59,1660],"2020-12-13",{"path":1887,"title":1888,"description":1889,"categories":1890,"draft":1662,"year":1891,"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.",[1701,1660],"2020-07-30",{"path":1893,"title":1894,"description":1895,"categories":1896,"draft":1662,"year":1897,"series":6},"\u002Fblog\u002Fintroduction-to-goroutines","Introduction to Goroutines","Understand the basics of concurrency and learn how to work with Goroutines in golang.",[53,1660],"2021-04-10",{"path":1899,"title":1900,"description":1901,"categories":1902,"draft":1662,"year":1903,"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.",[1660,1860,53],"2021-02-13",{"path":1905,"title":1906,"description":1907,"categories":1908,"draft":1662,"year":1909,"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.",[1660,1701],"2021-11-20",{"path":1911,"title":1912,"description":1913,"categories":1914,"draft":1662,"year":1915,"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",[1693,1692],"2022-04-09",{"path":1917,"title":1918,"description":1919,"categories":1920,"draft":1662,"year":1921,"series":6},"\u002Fblog\u002Flearn-unlearn-relearn","Learn - Unlearn - Relearn","Unlearning things to learn new is the way to grow. Discover how to do that!",[1679,1693],"2020-09-25",{"path":1923,"title":1924,"description":1925,"categories":1926,"draft":1662,"year":1927,"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.",[53,1660],"2021-07-07",{"path":1929,"title":1930,"description":1931,"categories":1932,"draft":1662,"year":1933,"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.",[59,1660],"2021-05-29",{"path":1935,"title":1936,"description":1937,"categories":1938,"draft":1662,"year":1939,"series":6},"\u002Fblog\u002Fmaking-decisions-the-right-way","Making Decisions: The right way","Decisions are hard! Learn how to make the right decisions always",[1679,1693],"2020-06-07",{"path":1941,"title":1942,"description":1943,"categories":1944,"draft":1662,"year":1946,"series":6},"\u002Fblog\u002Fmanage-logs-with-logrotate","Using Logrotate to manage logs","Learn how to use logrotate system utility to manage logs with example",[1945,1660],"Linux","2020-09-08",{"path":1948,"title":1949,"description":1950,"categories":1951,"draft":1662,"year":1952,"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.",[53,1660],"2020-03-31",{"path":1954,"title":1955,"description":1956,"categories":1957,"draft":1662,"year":1958,"series":6},"\u002Fblog\u002Fnotes-almanack-naval","Book Notes : Almanack of Naval Ravikant","My notes\u002Fhighlights from Almanack of Naval Ravikant book by Eric Jorgenson",[1692,1693],"2020-10-17",{"path":1960,"title":1961,"description":1962,"categories":1963,"draft":1662,"year":1964,"series":6},"\u002Fblog\u002Fnotes-anything-you-want","Book Notes : Anything you want","My notes\u002Fhighlights from Anything you want book by Derek Sivers",[1692,1693],"2021-09-25",{"path":1966,"title":1967,"description":1968,"categories":1969,"draft":1662,"year":1971,"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.",[1692,1970],"Startups","2020-11-03",{"path":1973,"title":1974,"description":1975,"categories":1976,"draft":1662,"year":1977,"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",[1692,1693],"2020-09-16",{"path":1979,"title":1980,"description":1981,"categories":1982,"draft":1662,"year":1983,"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",[1692,1970],"2020-01-07",{"path":1985,"title":1986,"description":1987,"categories":1988,"draft":1662,"year":1990,"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.",[1692,1989],"Entrepreneurship","2022-07-02",{"path":1992,"title":1993,"description":1994,"categories":1995,"draft":1662,"year":1997,"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.",[1692,1996],"Personal Finance","2021-02-26",{"path":1999,"title":2000,"description":2001,"categories":2002,"draft":1662,"year":2003,"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.",[1692,1970],"2020-04-26",{"path":2005,"title":2006,"description":2007,"categories":2008,"draft":1662,"year":2010,"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.",[1692,2009],"Design","2020-05-09",{"path":2012,"title":2013,"description":2014,"categories":2015,"draft":1662,"year":2016,"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.",[1692,1970],"2021-04-14",{"path":2018,"title":2019,"description":2020,"categories":2021,"draft":1662,"year":2023,"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.",[2022,1679],"Career","2023-03-05",{"path":2025,"title":2026,"description":2027,"categories":2028,"draft":1662,"year":2029,"series":6},"\u002Fblog\u002Fpersonal-okrs","Personal OKRs for Success","Why one should set personal OKRs and how to achieve success with them",[1679,1693],"2020-06-27",{"path":2031,"title":2032,"description":2033,"categories":2034,"draft":1662,"year":2036,"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.",[1693,2035],"Poker","2020-06-13",{"path":2038,"title":2039,"description":2040,"categories":2041,"draft":1662,"year":2042,"series":6},"\u002Fblog\u002Fpomodoro","Get work done: The Pomo Way","Learn to focus and get productive by following the Pomodoro Technique",[1679],"2020-10-24",{"path":2044,"title":2045,"description":2046,"categories":2047,"draft":1662,"year":2048,"series":6},"\u002Fblog\u002Fpostgres-constraints","Postgres Constraints","Constraints are line of defense for database. Explore various types of constrainsts in postgres",[1860,1660],"2020-11-07",{"path":2050,"title":2051,"description":2052,"categories":2053,"draft":1662,"year":2054,"series":6},"\u002Fblog\u002Fppf-explained","PPF Explained","Learn basics about Public Provident Fund and why you should invest",[1693,1996],"2020-12-24",{"path":2056,"title":2057,"description":2058,"categories":2059,"draft":1662,"year":2060,"series":6},"\u002Fblog\u002Fproductivity-chrome-extensions","Boost Productivity with Chrome Extensions","Utitizing chrome extensions to boost your productivity!",[1679,1702,1701],"2020-04-24",{"path":2062,"title":2063,"description":2064,"categories":2065,"draft":1662,"year":2066,"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.",[1679,1660],"2020-03-12",{"path":2068,"title":2069,"description":2070,"categories":2071,"draft":1662,"year":2072,"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.",[1692,1693],"2020-04-04",{"path":2074,"title":2075,"description":2076,"categories":2077,"draft":1662,"year":2078,"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.",[59,1660],"2021-10-03",{"path":2080,"title":2081,"description":2082,"categories":2083,"draft":1662,"year":2084,"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.",[53,1660],"2019-11-21",{"path":2086,"title":2087,"description":2088,"categories":2089,"draft":1662,"year":2090,"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.",[53,1860,1660],"2020-02-25",{"path":2092,"title":2093,"description":2094,"categories":2095,"draft":1662,"year":2096,"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.",[1715],"2020-07-17",{"path":2098,"title":2099,"description":2100,"categories":2101,"draft":1662,"year":2102,"series":6},"\u002Fblog\u002Fstack-in-golang","Implement Stack in Golang","Learn how to implement stack data structure in Golang (Full code)",[53,1660],"2020-09-14",{"path":2104,"title":2105,"description":2106,"categories":2107,"draft":1662,"year":2108,"series":6},"\u002Fblog\u002Fstart-oss-today","Start your Open Source journey today","Start your OSS journey with intro to GIT. Participate in Hacktoberfest!",[1802,1660],"2020-09-19",{"path":2110,"title":2111,"description":2112,"categories":2113,"draft":1662,"year":2115,"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.",[1660,2114],"Frontend","2021-02-05",{"path":2117,"title":2118,"description":2119,"categories":2120,"draft":1662,"year":2121,"series":6},"\u002Fblog\u002Fterm-insurance","Term insurance Simplified","Everything you need to know before you buy a term insurance.",[1693,1996],"2020-11-29",{"path":2123,"title":2124,"description":2125,"categories":2126,"draft":1662,"year":2128,"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",[1945,2127,1660],"Terminal","2020-09-06",{"path":2130,"title":2131,"description":2132,"categories":2133,"draft":1662,"year":2134,"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.",[1692,1693],"2020-05-19",{"path":2136,"title":2137,"description":2138,"categories":2139,"draft":1662,"year":2140,"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.",[53,1860,1660],"2020-03-18",{"path":2142,"title":2143,"description":2144,"categories":2145,"draft":1662,"year":2146,"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.",[53,1660],"2022-05-31",{"path":2148,"title":2149,"description":2150,"categories":2151,"draft":1662,"year":2153,"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",[1693,2152],"Tech","2024-06-01",{"path":2155,"title":2156,"description":2157,"categories":2158,"draft":1662,"year":2159,"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!",[1693],"2020-12-31",{"path":2161,"title":2162,"description":2163,"categories":2164,"draft":1662,"year":2165,"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!",[1693],"2021-12-31",1788773187365]