<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>banters</title>
        <link>https://paragraph.com/@banters</link>
        <description>Anything and everything under the sun</description>
        <lastBuildDate>Wed, 22 Apr 2026 04:52:57 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <image>
            <title>banters</title>
            <url>https://storage.googleapis.com/papyrus_images/fe6e54ea2e3786e278c570e5529cc3dd</url>
            <link>https://paragraph.com/@banters</link>
        </image>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[America needs to update its immigration system]]></title>
            <link>https://paragraph.com/@banters/america-needs-to-update-its-immigration-system</link>
            <guid>N04DniEUDrcskQnIDZu8</guid>
            <pubDate>Tue, 19 Dec 2023 00:46:03 GMT</pubDate>
            <description><![CDATA[If America doesn’t attract highly skilled people from all around the world to come work in America, sooner or later innovation will move out]]></description>
            <content:encoded><![CDATA[<p><span data-name="wave" class="emoji" data-type="emoji">👋</span><em> Hey,&nbsp;</em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out" href="https://twitter.com/shrimalmadhur"><em>Madhur</em></a><em>&nbsp;here!&nbsp;Welcome to my Newsletter. I write about technology and lifestyle. Subscribe to my newsletter to receive all my posts directly in your inbox. Happy reading</em></p><p>This tweet by <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out" href="https://x.com/realGeorgeHotz/status/1735708811024060499?s=20">George Hotz</a> hits home as I am someone who has been experiencing this VISA process for years now.</p><img src="https://storage.googleapis.com/papyrus_images/6db68fffd4137308280c8921903244d5.png" alt="" blurdataurl="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAQCAIAAAD4YuoOAAAACXBIWXMAAAsTAAALEwEAmpwYAAACt0lEQVR4nLWTUU/TUBTHS+3t3aXZmrZsLYMNmBgkhMSQwcLG1nWllu623HW1q5cykAcSZ0J40gdffNcnP4UfzO/gq2a9BFCJGiK/3DT/3jbn/M8593Lcw8N/fv8m2KuvPlk7Pz9/PZmkaRrH8Uuapu8+PQvfchw3w/P3iCtJkiAIHMrNfv/29cvHD8WS3jG7rtffaTR3Gs1ma6/e6iJVn1q4leC2/n3zzq/cXEHOiSLP8xDmRAgRmpUkCSEEIZz5+U8h45co7JV/xN+dRpblnm33bJuQwSAMMfYbjYZlWUEQxHGy1+54ntf3fcdxHNe1rF6SJD72w3DY9/0gCGzbHkaR67ppmr46O0to0rPtnUbjJoeiKGmaUnp0gPsY+0mSWJaVULq+vq5lqKrKnoqi5PN59RaapskZqqoWCgVZlovFoqZpCKGbClRV3d3d3dzcrNfrGxsbtYzt7W1N07j/BQBg2j+eZ/2djj47A5IkQQjFbAEAoCiyNdXTUSFBEAAATEAIJUkCGTCDxeEghIQMEkrdjJ5tY4zb7TYh5JCQIAhY0+I4Pj099TxvPD4ZRlGr1er7vuu6SUJHo1HHNNP02PM8x3EGYUjpUZoeO87zqyEf4P4wivYdZzweY4zDcOi4brPZ6pjmISGmaXqeF0exbe8DAFhZzCnKuLbM8/y1ZiVe9ae8sGAYRqVSWVt7qmlz8+WyruulKTqjWl0yDKNcnr/7mP91AKo6nTuzxm4A04UM5qVQkPP5PNuR5alWFOWqy39GUZTJZBJFkWl2KaXDKMIYE0IopY7rvojjra2tIAgOcJ+QgWl2DwkZjUZBEIzHJ6qq/msRIoQCANenSIQwh5AAALOMELpPcxgIzS4trywtryxWKvPlcq22WirplWp1pfbYMIyLi4vLy8uebS8sLuq6cc8cD8oPep+Jd9mId2AAAAAASUVORK5CYII=" nextheight="580" nextwidth="1194" class="image-node embed"><p>Let me give you an example. If you are an Indian Citizen who has studied in a pretty good engineering college in India and wanted to come study and/or work in the US, the process is quite intimidating and it doesn’t end. First, you get an F1 visa for studying, and then once you graduate you work on OPT (which has certain years you can work on) in parallel, you apply for your H1B, which is a lottery-based system, that is capped at 85000 per year (60000 for general and 20000 for higher education). Close to 500k people <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out" href="https://redbus2us.com/h1b-visa-cap-reach-dates-history-graphs-uscis-data/">apply</a> each year for H1B.</p><p>Now once you have an H1B, it’s not over because it’s only valid for around 3 years. Every 3 years you have to renew - submit a lot of documents and if you go out of the US, you have to get a stamp on your passport. This process is so painful since you have to fill out online forms every time. </p><p>And if you change your job, your visa needs to be transferred to the new company. H1B is tied to your employer. </p><p>Ok, so what about Permanent Residency? If you are an Indian in an EB2 category, you can forget about getting a green card. Legally on H1B, you can’t earn money from other jobs and if you get laid off, which has been happening quite frequently, you just have 2 months to find a job otherwise say goodbye to your American Dream. </p><p>In addition to all of this, you are always tense about your visa status, travel, etc. </p><p>Even though I just described how the process is for Indians, I think the general work VISA process applies to a lot of other countries.</p><p>Now why am I talking about the VISA process? Well, people want to come to America to pursue their dreams for multiple reasons: Good quality of life, access to capital, hustle culture, and a lot of great diverse-minded people to work with. So even though the VISA process is so stressful and painful, people still want to come here and build great things. </p><p>But recently the rules of the game have been changing. Why?</p><ul><li><p>General globalization and access to most things over the internet</p></li><li><p>The COVID-19 pandemic has proved that people can work remotely and they don’t need to physically be present in the office to be successful </p></li><li><p>The rise of countries like India and China has seen capital moving toward Asian countries</p><p></p></li></ul><p>Because of the changes, people have started evaluating whether is the process worth the pain or if they can achieve whatever they want in their home country or any other country. The rules of the game are changing and the US Visa process to let people come in is still old and not keeping up with the pace of the changing world. Particularly somehow it’s becoming hard for people who are highly skilled to have more opportunities. </p><p>There are also some concerns about more seamless immigration</p><ul><li><p>What happens to the American people? Do they lose their jobs?</p></li><li><p>People only immigrate to only few cities like San Francisco, New York, Seattle, etc., driving the prices up and pushing the less skilled people out of that area</p></li></ul><p>I agree those are valid concerns but the solution is to not make high-skilled immigration hard. America is the land of immigrants. Maybe government should try to incentivize people to move to tier-2, and tier-3 cities and provide good infrastructure for someone to up their skills. With a lot of issues bubbling up with respect for China, maybe America can bring up more manufacturing industries. </p><p>Let’s be clear about one thing - the world works on survival of the fittest. If an adult person doesn’t up their skills game (considering the government provides enough access to good infrastructure) then they will not survive. If America doesn’t attract highly skilled people from all around the world to come work in America, sooner or later innovation will move out.</p><p>I think it’s worth making sure America remains what it has been, a place for great technological innovation. I believe America does need a lot of great leaders in higher government positions who, instead of stopping finding ways to curb the speed of innovation, can push innovation faster. The world will not stop and America needs enough manpower to roll with it. </p><hr><p><em>If you enjoyed reading this you may be interested in following me on </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out" href="https://twitter.com/shrimalmadhur"><em>Twitter</em></a><em> and </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out" href="https://medium.com/@shrimalmadhur"><em>Medium</em></a><em>.&nbsp;</em></p>]]></content:encoded>
            <author>banters@newsletter.paragraph.com (banters)</author>
            <category>immigration</category>
            <category>america</category>
            <enclosure url="https://storage.googleapis.com/papyrus_images/6b05ac2b426cd9e0dd7e2b6547077144.jpg" length="0" type="image/jpg"/>
        </item>
        <item>
            <title><![CDATA[Retirement]]></title>
            <link>https://paragraph.com/@banters/retirement</link>
            <guid>UyYfArNg6TW9USSmnWJa</guid>
            <pubDate>Thu, 05 Oct 2023 02:29:23 GMT</pubDate>
            <description><![CDATA[When do you think we should retire?” Robert asked this question to one of her close friends Seema while they were si...]]></description>
            <content:encoded><![CDATA[<p>“When do you think <strong>we should retire</strong>?” Robert asked this question to one of her close friends Seema while they were sitting in their usual coffee shop on a chilly Saturday morning. It was a good sunny day and the shop was quite packed: someone working on their laptop, a group of friends playing board games, and other people just having casual conversations with each other. They have been meeting once every few months just to catch up as they both are married and have full-time jobs which keeps them busy. </p><p>Seema thought about it and the first question came to her mind which she immediately spit out “What does it mean to retire?”. As with most of life’s questions, this is another subjective question which when asked to 100 other people, everyone has a different answer. Answers like I should have $10 million dollars or some arbitrary amount of money are very common. </p><p>They both thought about it for a minute.</p><p>Robert started thinking about another strain of thoughts — does retirement also mean I will stop working? He asked Seema this question and now there are two questions to answer - When to retire (retirement criteria)? and does retirement also mean you are not working? </p><p>Seema: “I think for me retirement is something when I’ve enough money so that I can work on things which I really want to without worrying about if I’m making money off those things or not. I do want to work after I <em>retire</em> but only on things of my choice.”</p><p>Robert: “That does come with a question that how much money is enough. Is there an absolute enough? Would you stop if you have an absolute enough? With more money habits also change.”</p><p>Seema: “You have to promise yourself that you will live the same life even if you get enough but I get your point. Things can change when I’ve more money — I could want to go on more vacations, but more stuff. Oh well my enough money will not be enough”</p><p>Both giggled at that sentence and continued sipping on their coffee. </p><p>Seema: Hmm I also think that retirement could be an overloaded term. Are you considered retired if you quit your 9 to 5 and work on your own stuff? </p><p>Robert: Maybe not</p><p>Seema: Then maybe it’s a wrong question to be thought about. Maybe the right question is, what would it take for you to quit your 9 to 5 without having to worry about money?</p><p>Robert took a deep breath and thought about this question. Seema observed his face with a slight smile. </p><p>Seema: I can see it on your face that you are as confused as I am but we don’t have to think it right now.</p><p>It was almost lunchtime now and they both thought it would be good to head out and get something to eat. </p><hr><p>What does retirement mean to you? Give it a thought.</p><p></p>]]></content:encoded>
            <author>banters@newsletter.paragraph.com (banters)</author>
            <category>lifestyle</category>
            <category>thoughts</category>
            <enclosure url="https://storage.googleapis.com/papyrus_images/17de17f052045a36f13ee4df4b346ce4.jpg" length="0" type="image/jpg"/>
        </item>
        <item>
            <title><![CDATA[Tutorial: Building an ERC1155 SoulBound Token]]></title>
            <link>https://paragraph.com/@banters/tutorial-building-an-erc1155-soulbound-token</link>
            <guid>jtHVrvnsvJPhkUDxTR6c</guid>
            <pubDate>Thu, 05 Oct 2023 02:13:58 GMT</pubDate>
            <description><![CDATA[Photo by Markus Spiske on&nbsp;UnsplashWhat does SoulBound mean?According to Vitalik’s writings here:A soulbound item, once picked up, cannot be trans...]]></description>
            <content:encoded><![CDATA[<hr><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/a269ca5813502c031c5d8db66104dc03.jpg" class="image-node embed"><figcaption htmlattributes="[object Object]" class="">Photo by <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out markup--anchor markup--figure-anchor" href="https://unsplash.com/@markusspiske">Markus Spiske</a> on&nbsp;<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out markup--anchor markup--figure-anchor" href="https://unsplash.com">Unsplash</a></figcaption></figure><p></p><h3>What does SoulBound mean?</h3><p>According to Vitalik’s writings <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out markup--anchor markup--p-anchor" href="https://vitalik.ca/general/2022/01/26/soulbound.html">here</a>:</p><blockquote><p><em>A soulbound item, once picked up, cannot be transferred or sold to another player.</em></p></blockquote><p>In this article, he also mentions bringing this property to NFTs where once you acquire (mint or airdropped) this token, you can’t transfer it. This means you won’t be able to sell it in any marketplace.</p><p>One of the clear use cases of this property is in <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out markup--anchor markup--p-anchor" href="https://poap.xyz/">POAP</a>. As Vitalik writes:</p><blockquote><p><em>Perhaps the best example of a project trying to do this is </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out markup--anchor markup--blockquote-anchor" href="https://poap.xyz/"><em>POAP</em></a><em>, the “proof of attendance protocol”. POAP is a standard by which projects can send NFTs that represent the idea that the recipient personally participated in some event.</em></p></blockquote><p>This is a pretty interesting concept to me so I wanted to implement it myself for one of my projects (more on that in future posts). Therefore I am also sharing a quick tutorial to write a very simple ERC-1155 contract with this property.</p><h3>Prerequisites</h3><ul><li><p>Basic knowledge of <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out markup--anchor markup--li-anchor" href="https://ethereum.org/en/developers/docs/smart-contracts/">smart contracts</a></p></li><li><p>Basic knowledge about <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out markup--anchor markup--li-anchor" href="https://soliditylang.org/">Solidity</a> and ERC-1155</p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out markup--anchor markup--li-anchor" href="https://book.getfoundry.sh/">Foundry</a> installed — You can also use hardhat if you are more familiar with it, but this tutorial assumes you are using Foundry</p></li></ul><h3>Steps</h3><ol><li><p>Create a new project using</p></li></ol><pre class="dont-break-out text-sm md:text-base"><code>forge init soulbound</code></pre><p>This will create a new project with a sample smart contract Counter and your project structure should look like this</p><img src="https://storage.googleapis.com/papyrus_images/bd932ece4cf19383247f60581555cd3a.jpg" blurdataurl="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAACXBIWXMAAAsTAAALEwEAmpwYAAAE7UlEQVR4nKVW3W/TVhx10zahDk6ub+LcuBfX+WgInvhIFzUNpDV4kQmha5oVpagrnrW0KopoloaC5U1kBqJFFIg6TV0VxFBXMWloUiWe9rjnPU3THjZp4o+YeNrDtE6JBwUeUOseHdnX0pWP7+/8PkwghAAA0WiU53lJkmZmZnK5XLVazeVy6XS6UCgoihIMBimKgpZAIIQoihIEAWOsKEqtVtM0bbmDcrlc6YDjOACARQE/y9LQ62dZH0JOykV04Ojra99sNoIgnBRFQ+hlGGskkAe6nQ7MouGh45EQPxJ/97uNb1rrazd07euvvhyJxw46ury0y0e7vLQLupy7pPfFfgIFogAPDhyJ4egJNxsals5f0W8PS1kpd3Hy0gKODjn9AZqLHEABpz/g4Q7vkk5/wI0HPdxhgrtwE8jXvOeXuQuGN6vFlx4MzjbYiVpUvec5dz04XWcnar5xParef2du1Tf+qTt9zZPR3k4gX42q9/AHnwP5KoEnb3anLjvEkjDX9Jy7vvnb829/fT7ZePrz8+2nz/75/d/tH/74u/Hjsz+3tzd/+cstV7tTl+2jpbfwgHiFiKvF9Z+Glx4QcZWg5IWeMRVk5nvFj4iTii2lOKSPe0+rwof68Fx9bHFldHElefmL04sr8bnbPWOq/XRxN+wdK5qb2yZDl5PrZ48KUQ77z4ylzqalfG58MjcRCvIEQRyw9/R1d/V1d5GOXi/tNt3bBf/fSfiQ3wVojhs4fuIEy7KlUsm4detGrdZqtWKxIRpChPwM4/Mh5EPI4/HScFf0eNqkobddaAAAnucBAAxCNluP3W43q8Fms5EdUBRlLtp7GGbPldwWCAaBi5z4pMZHjy6VFw3DqFQquq63Wi1N01RVnZ6e1nVd0zSM8Z6qeucEENKHQhEXoGOxmCRJ2Ww2lUqNj4+Lojg6OiqKYiaTSaVSe24VLwUwxl6PB2PMsixFUXa7nSRJ82rCXFsU4Dju1MmTfDBoGMb6+rosyxRFIYSYV7DXV795AghhX3eXHyEaQpIkbZ1OR3SsNm238PlvmHzwzKUSGwjnc7lCoZBOp6empubn5/P5vCiKiqJIkkSSpNUs4nmvhx567zw6xF2cni6Xy9VqtVgs1uv1Uqk0Oztbr9f3KwAhdPb0HCRJMzKmq7ZOfEzPrQ21HZOTyWQoHK5UKo8ePWo0GhhjCOGrJluzekfg0ABPORwjiUQ2mxVFkWGYlwlKURQAwFxYFOD5AA3cRxIpCsBwKMTzPMdxgiAcO3Ys0oH5GI1G9zqcX8uis8UKNygslct37qzU63XDMB4/fnz37t2ZmZlqtbqxsTE1NWWz2fYUqB2TaQDcLhfVAcMwZj0zDGNWXDAY5HkeIWQ5RHxs5FT/QDsyiqKoqirLciaTkWW5UChwHGetyl4TOBpP0NCbz+e3trYMw9ja2tI0Tdd1wzAikYiFRv2GAAchAADQEJqNgaIosyCIF4NhvycYO/d+/wA/kkh8/+RJs9ms1WqNRmNtbW15eXl1dXVhYWG/An62nyTJZDJZKpWSyWQikUin05lM5uVs2F+z4/nRM1JocFAQjpiZzrKs+c/LdX5MMcamE1YE3C5XOByufGYMjZyqLi09fPiw2Wxubm62Wi1d15vN5loHuVzObrdbbHYsyyLk73gMzelmQhAElmUxxpZnzn/4fLSDKp768AAAAABJRU5ErkJggg==" nextheight="530" nextwidth="532" class="image-node embed"><p>2. You can either create a new contract under the <code>src</code> directory or work with the existing Counter.sol</p><p>3. We will be using the OpenZepplin <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out markup--anchor markup--p-anchor" href="https://docs.openzeppelin.com/contracts/4.x/">contracts</a> library for implementing our token so we need to install that. Foundry uses git submodules for importing libraries. The below command will help you with this installation</p><pre class="dont-break-out text-sm md:text-base"><code>forge install OpenZeppelin/openzeppelin-contracts</code></pre><p>4. Once installed you are ready to write your smart contract. The next step is to import your dependencies into your contract. You can use the below command to import the ERC1155 library you just installed</p><pre class="dont-break-out text-sm md:text-base"><code>import "openzeppelin-contracts/contracts/token/ERC1155/ERC1155.sol";</code></pre><p>5. Since we are focused on soulbound tokens in this tutorial, we will just see how to make your contract behave like one. The rest of the code remains the same as what a normal ERC-1155 contract would look like. ERC-1155 has a method called <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out markup--anchor markup--p-anchor" href="https://docs.openzeppelin.com/contracts/3.x/api/token/erc1155#ERC1155-_beforeTokenTransfer-address-address-address-uint256---uint256---bytes-">_beforeTokenTransfer</a> which is a <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out markup--anchor markup--p-anchor" href="https://docs.openzeppelin.com/contracts/3.x/extending-contracts#using-hooks">Hook</a> that will be called before any transfer of token is done. We will override this method so that it behaves like a soulbound token</p><pre class="dont-break-out text-sm md:text-base"><code>function _beforeTokenTransfer(
   address operator,
   address from,
   address to,
   uint256[] memory ids,
   uint256[] memory amounts,
   bytes memory data
) pure override internal {
  require(from == address(0) || to == address(0), "This a Soulbound     token. It cannot be transferred. It can only be burned by the token   owner.");
}</code></pre><p>Let me explain the most important piece of code <code>from == address(0) || to == address(0)</code>. The first condition says that if the token is minted (minted token originates from 0 address) and the second condition says if the token is burned (tokens get burned to 0 address). So only if the token is minted or burned, this method will execute the transfer otherwise it will fail in this <code>require</code> condition. One line of code and you can make it a soulbound token. Pretty impressive.</p><p>6. You can now deploy your contract using <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out markup--anchor markup--p-anchor" href="https://book.getfoundry.sh/reference/forge/forge-create">forge create</a> command and after you mint a token if you try to transfer that it won’t allow you to transfer. The only thing you can do with this token is to burn it.</p><p>If you want to look at the full example you can take a look <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out markup--anchor markup--p-anchor" href="https://github.com/shrimalmadhur/kudos-contract/blob/main/src/NFTContract.sol">here</a>. I hope this was useful. Please subscribe to my newsletter if you want my writings directly in your inbox.</p><hr><p><em>If you enjoyed reading this you may be interested in following me on </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out markup--anchor markup--p-anchor" href="https://twitter.com/shrimalmadhur"><em>Twitter</em></a><em> and </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out markup--anchor markup--p-anchor" href="https://shrimalmadhur.substack.com/"><em>Substack</em></a><em>.</em></p>]]></content:encoded>
            <author>banters@newsletter.paragraph.com (banters)</author>
            <category>blockchain</category>
            <category>cryptocurrency</category>
            <category>tutorial</category>
        </item>
        <item>
            <title><![CDATA[Go embedding by example]]></title>
            <link>https://paragraph.com/@banters/go-embedding-by-example</link>
            <guid>i6N1R697MAfNr06BVlxm</guid>
            <pubDate>Fri, 23 Dec 2022 04:08:42 GMT</pubDate>
            <description><![CDATA[I recently learned about Go Embedding  structs and interfaces and I was quite impressed by how powerful it can be. So in the process of learning and e...]]></description>
            <content:encoded><![CDATA[<a target="_blank" rel="noopener noreferrer nofollow ugc" style="cursor: pointer;"><img class="image-node embed"></a><p>I recently learned about <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out" href="https://gobyexample.com/struct-embedding">Go Embedding</a>  <code>structs</code> and <code>interfaces</code> and I was quite impressed by how powerful it can be. So in the process of learning and exploring, I thought it might be good to share what I have learned with a small and hopefully easy example.</p><p>I have divided this example into 3 simple projects which will explain the use case and how embedding can be a really powerful programming paradigm.</p><p>The <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out" href="https://github.com/shrimalmadhur/playground/tree/main/go-embedding/first">first</a> project is where we define an interface with two methods:</p><pre class="dont-break-out text-sm md:text-base"><code>package types

import "context"

type Client interface {
	MethodA(ctx context.Context, message string)

	MethodB(ctx context.Context, message string)
}</code></pre><p>And then we also define a <em>service</em> which is used to initialize a <em>client</em> that will implement these methods</p><pre class="dont-break-out text-sm md:text-base"><code>package types

import (
	"context"
)

type Service struct {
	client Client
}

func NewService(client Client) *Service {
	return &amp;Service{client: client}
}

func(s *Service) MethodA(ctx context.Context, message string) {
	s.client.MethodA(ctx, message)
}

func(s *Service) MethodB(ctx context.Context, message string) {
	s.client.MethodB(ctx, message)
}</code></pre><p>This means that when we initialize using <code>NewService</code> using a <em>client</em> then it will use the <em>client</em> implemented methods.</p><p>Now the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out" href="https://github.com/shrimalmadhur/playground/tree/main/go-embedding/third">third</a> project (pardon my ordering, second will come in a bit) is a library which has an implementation of <code>first.Client</code></p><pre class="dont-break-out text-sm md:text-base"><code>package third

import (
	"context"
	"fmt"
	"github.com/shrimalmadhur/playground/interfaces/first/types"
)

type Client struct {
	 client types.Client
}

func (c Client) MethodA(ctx context.Context, message string) {
	fmt.Println(fmt.Sprintf("client impl message MethodA: %s", message))
}

func (c Client) MethodB(ctx context.Context, message string) {
	fmt.Println(fmt.Sprintf("client impl message MethodB: %s", message))
}

func NewClient() Client {
	return Client{}
}</code></pre><p>Here is the final <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out" href="https://github.com/shrimalmadhur/playground/tree/main/go-embedding/second">second</a> project which brings it all together and where we will see actual power of embedding.</p><p>It has a file called <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out" href="https://github.com/shrimalmadhur/playground/blob/main/go-embedding/second/client/client.go">client.go</a> which contains</p><pre class="dont-break-out text-sm md:text-base"><code>import (
	"context"
	"fmt"
	cl "github.com/shrimalmadhur/playground/interfaces/third"
)

type Client struct {
	cl.Client
}

func (s Client) MethodA(ctx context.Context, message string) {
	fmt.Println(fmt.Sprintf("Override MethodA message: %s", message))
}

func NewClient() Client {
	sdkClient := cl.NewClient()
	return Client {
		sdkClient,
	}
}</code></pre><p>Now what you see here is</p><pre class="dont-break-out text-sm md:text-base"><code>type Client struct {
	cl.Client
}</code></pre><p>This above syntax is called <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out dont-break-out" href="https://gobyexample.com/struct-embedding">embedding</a> where you import and override the methods of the actual <em>client</em> if you want.</p><p>In the <code>NewClient</code> function we initialize the the <code>sdkClient</code> with <code>third.NewClient</code> which will import the two method using Go embedding. But here we have an option to override any of the <code>MethodA</code> or <code>MethodB</code>, so we override <code>MethodA</code> to see what happens.</p><p>To run all of this here is our <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out" href="https://github.com/shrimalmadhur/playground/blob/main/go-embedding/second/main.go">main.go</a> file </p><pre class="dont-break-out text-sm md:text-base"><code>package main

import (
	"context"
	"github.com/shrimalmadhur/playground/interfaces/first/types"
	"github.com/shrimalmadhur/playground/interfaces/second/client"
)


func main()  {
	ctx := context.Background()

	myClient := client.NewClient()

	service := types.NewService(myClient)

	service.MethodA(ctx, "hello")

	service.MethodB(ctx, "hello")
}</code></pre><p>So now here is what it prints </p><pre class="dont-break-out text-sm md:text-base"><code>Override MethodA message: hello
client impl message MethodB: hello</code></pre><p>We can see in the above print messages that the first line has been printed using the overridden <code>MethodA</code> in the <code>main</code> package and the second line is printed using the <code>client</code> library in the <code>second</code> package. This way you can import a <code>client</code> package and then override the interface <code>methods</code> as needed. </p><p>I hope this makes it easy to understand Go embedding. Any feedback is welcome. </p><p>You can see the full code <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out dont-break-out" href="https://github.com/shrimalmadhur/playground/tree/main/go-embedding">here</a>.</p>]]></content:encoded>
            <author>banters@newsletter.paragraph.com (banters)</author>
            <category>programming</category>
            <category>go</category>
            <category>golang</category>
            <category>go-embedding</category>
        </item>
    </channel>
</rss>