<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Girish Koundinya</title>
    <description>The latest articles on Forem by Girish Koundinya (@_tink3r).</description>
    <link>https://forem.com/_tink3r</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F158038%2Fdc4214ce-c3b1-41b4-ad31-d358f874395c.jpg</url>
      <title>Forem: Girish Koundinya</title>
      <link>https://forem.com/_tink3r</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/_tink3r"/>
    <language>en</language>
    <item>
      <title>Payments are Async</title>
      <dc:creator>Girish Koundinya</dc:creator>
      <pubDate>Sun, 05 Nov 2023 14:09:00 +0000</pubDate>
      <link>https://forem.com/_tink3r/payments-are-async-4i82</link>
      <guid>https://forem.com/_tink3r/payments-are-async-4i82</guid>
      <description>&lt;p&gt;~~~ This post was originally published in my &lt;a href="https://blog.koundinya.xyz/posts/what-i-learned-from-payments/"&gt;blog&lt;/a&gt; ~~~&lt;/p&gt;

&lt;p&gt;As a founding engineer at &lt;a href="https://inai.io/"&gt;inai&lt;/a&gt;, a payment orchestration platform that integrates with hundreds of payment methods and gateways worldwide, I've had the opportunity to learn a lot about the complexities of global payments. Before inai, I worked in the customer support SaaS software space, so a lot of the payment gateway terminology and nuances were new to me. Also made me remember the wise words of an &lt;a href="https://insanecoding.blogspot.com/2014/02/http-308-incompetence-expected.html"&gt;Angry Hacker&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"The Internet from every angle has always been a house of cards held together with defective duct tape. It’s a miracle that anything works at all. Those who understand a lot of the technology involved generally hate it, but at the same time are astounded that for end users, things seem to usually work rather well.&lt;br&gt;
"&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Turtles all the way down: What happens when you swipe your card
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2RE0zO5---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://firebasestorage.googleapis.com/v0/b/firescript-577a2.appspot.com/o/imgs%252Fapp%252FGirishKoundinya%252F10KYef5FbT.png%3Falt%3Dmedia%26token%3Dae804629-3b8c-4aea-8351-cf45c14d1d6a" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2RE0zO5---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://firebasestorage.googleapis.com/v0/b/firescript-577a2.appspot.com/o/imgs%252Fapp%252FGirishKoundinya%252F10KYef5FbT.png%3Falt%3Dmedia%26token%3Dae804629-3b8c-4aea-8351-cf45c14d1d6a" alt="Payment Chain" width="800" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you swipe your credit or debit card, it initiates a complex sequence involving the cardholder, merchant, acquirer (merchant's bank), processor, card network, and issuing bank. The process starts with the card swipe, information flows through these entities for authorization, and if approved, a series of authorization messages are relayed, culminating in the completion of the transaction.&lt;/p&gt;

&lt;p&gt;It sounds and looks beautiful. When it works.&lt;/p&gt;
&lt;h2&gt;
  
  
  Payments are not final
&lt;/h2&gt;

&lt;p&gt;When I was a payments noob, I thought that receiving a 200 response from Stripe meant that a merchant was going to get paid. I learned that's not true, while close to the truth a 200 response from the payment gateway ONLY indicates that the payment gateways has received the request to kick start a complex payment process.&lt;/p&gt;

&lt;p&gt;As the UML diagram above shows, there are many steps that can fail after a 200 response from the payment gateway. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The acquirer may decline the transaction.&lt;/li&gt;
&lt;li&gt;The issuer may decline the transaction.&lt;/li&gt;
&lt;li&gt;The processor may experience a technical outage.&lt;/li&gt;
&lt;li&gt;The merchant's bank account may be insufficiently funded.&lt;/li&gt;
&lt;li&gt;The customer may file a chargeback.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In any of these cases, the merchant will not receive payment. There are tons of such examples in Patrick McKenzie's &lt;a href="https://www.bitsaboutmoney.com/archive/no-payments-are-final"&gt;blog&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is why it is important for merchants to understand the difference between HTTP status codes and transaction statuses. An HTTP status code of 200 simply means that the payment gateway has received the request and processed it successfully. It does not mean that the transaction has been approved or that the merchant will receive payment.&lt;/p&gt;

&lt;p&gt;This is also why it is important for merchants to implement webhook handling. Webhooks allow merchants to receive real-time notifications about the status of their transactions. This way, merchants can be alerted to any problems immediately and take corrective action if necessary.&lt;/p&gt;
&lt;h3&gt;
  
  
  HTTP status != Transaction Status
&lt;/h3&gt;

&lt;p&gt;An HTTP status code is a three-digit number that indicates the result of an HTTP request. The most common HTTP status codes are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;200 OK: The request was successful.&lt;/li&gt;
&lt;li&gt;400 Bad Request: The request was malformed or incomplete.&lt;/li&gt;
&lt;li&gt;401 Unauthorized: The client is not authorized to access the resource.&lt;/li&gt;
&lt;li&gt;404 Not Found: The resource does not exist.&lt;/li&gt;
&lt;li&gt;500 Internal Server Error: An unexpected error occurred on the server.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A transaction status is a different concept. It indicates the state of a payment transaction. &lt;/p&gt;

&lt;p&gt;Here is an example where Stripe says 200 OK but the transaction status JSON shows that the transaction has failed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "id": "ch_1234567890",
  "object": "charge",
  "amount": 1000,
  "currency": "usd",
  "status": "failed",
  "failure_code": "card_declined",
  "failure_message": "The card was declined by the issuing bank."
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This response indicates that Stripe received and processed the payment request successfully, but the transaction was ultimately declined by the issuing bank. This could happen for a variety of reasons, such as insufficient funds in the customer's account or a suspected fraudulent transaction.&lt;/p&gt;

&lt;p&gt;Even though the transaction failed, Stripe will still return a 200 OK HTTP status code. This is because the HTTP status code is only indicative of the success of the API call, not the outcome of the transaction itself.&lt;/p&gt;

&lt;p&gt;To get the true status of a transaction, merchants should always inspect the transaction status JSON. If the status is failed, then the merchant should take appropriate action, such as notifying the customer of the declined transaction.&lt;/p&gt;

&lt;h3&gt;
  
  
  Webhook handling is as important as the API call
&lt;/h3&gt;

&lt;p&gt;Webhook handling is an important part of any payments system. It allows merchants to receive real-time notifications about the status of their transactions. This way, merchants can be alerted to any problems immediately and take corrective action if necessary, so if you are evaluating a payment gateway integration, don't just evaluate the APIs, also make headroom for the callback and how you can eventually identify the status of a payment.  &lt;/p&gt;

&lt;p&gt;For example, a merchant could use webhooks to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Be alerted to declined transactions so that they can contact the customer and resolve the issue.&lt;/li&gt;
&lt;li&gt;Be alerted to refunds so that they can update their inventory and customer records.&lt;/li&gt;
&lt;li&gt;Be alerted to chargebacks so that they can dispute them with the payment processor.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  My key takeaways from working with different payment gateways are:
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Asynchronous payments are the norm.
&lt;/h4&gt;

&lt;h4&gt;
  
  
  2. Callbacks are equally important as API calls.
&lt;/h4&gt;

&lt;h4&gt;
  
  
  3. Understand different types of transaction codes.
&lt;/h4&gt;

&lt;h4&gt;
  
  
  4. Imagine the whole payments network as if it were discworld
&lt;/h4&gt;

&lt;p&gt;After completing tons of payment integrations, I couldn't help imagining if Terry Prachett would compare a payments system to great a'tuin and 4 elephants. &lt;/p&gt;

&lt;p&gt;Why imagine when you can ask ChatGPT to describe it in Terry Pratchett style ?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"Think of the payment system as the Discworld itself, a flat world perched on the backs of four colossal elephants, which, in turn, stand atop the shell of a giant turtle. It's a realm where coins spin like the stars and payments flow like magical rivers. But beware, for in this fantastical place, financial transactions are a cosmic ballet, where money appears and vanishes, and commerce is a surreal adventure amidst guilds, wizards, and curious creatures. It's a realm where the improbable is the norm, much like the Discworld itself"&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z_c6wUFL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://media.istockphoto.com/id/1278491239/photo/four-mighty-world-elephants-stand-upon-the-carapace-of-great-atuin-the-world-turtle-and-upon.jpg%3Fs%3D1024x1024%26w%3Dis%26k%3D20%26c%3DT39-TbdIq3s1KveFUxu1dJGxKvYGBqqOqD2sdGFNCUU%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z_c6wUFL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://media.istockphoto.com/id/1278491239/photo/four-mighty-world-elephants-stand-upon-the-carapace-of-great-atuin-the-world-turtle-and-upon.jpg%3Fs%3D1024x1024%26w%3Dis%26k%3D20%26c%3DT39-TbdIq3s1KveFUxu1dJGxKvYGBqqOqD2sdGFNCUU%3D" alt="Discworld Payments" width="800" height="734"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>payments</category>
      <category>integrations</category>
      <category>gateways</category>
    </item>
    <item>
      <title>Elo Ratings, Ruby and Cricket</title>
      <dc:creator>Girish Koundinya</dc:creator>
      <pubDate>Fri, 26 Feb 2021 03:55:41 +0000</pubDate>
      <link>https://forem.com/_tink3r/elo-ratings-ruby-and-cricket-2ef3</link>
      <guid>https://forem.com/_tink3r/elo-ratings-ruby-and-cricket-2ef3</guid>
      <description>&lt;p&gt;~~~ This post was originally published in my &lt;a href="https://blog.koundinya.xyz/posts/elo_rating_cricket/"&gt;blog&lt;/a&gt; ~~~&lt;/p&gt;

&lt;p&gt;I’ve started watching a lot of chess streams during the lockdown. The quartet of Anish Giri, Vidit, Sagar Shah and Samay Raina have rekindled my curiosity in Chess and while my low rating at chess.com clearly indicates I haven’t progressed much, I do enjoy a 5 minute chess game when I can.&lt;/p&gt;

&lt;p&gt;India toured Australia recently the battle was a joy to behold. Never had I been so hooked on to Test cricket as I was during the series.&lt;/p&gt;

&lt;p&gt;If you are question is “What do I do with these two pieces of trivia about how you spent your lockdown?”. I would say that’s a fair question. My new found interests reminded me of a side project I had worked on in 2019.&lt;/p&gt;

&lt;p&gt;In 2019, I had recently joined the platform engineering team at Freshworks and the Cricket World Cup had just begun. We played a game within the team, the aim was to see who got most match predictions right.&lt;/p&gt;

&lt;p&gt;As developers do, our first step when faced with any challenge is to open a jira ticket open Google Sheets. It had a column for each participants and rows indicating the different matches and venue for each match.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pB8kUyLT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdd8qhsnsdlotkttkbfm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pB8kUyLT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdd8qhsnsdlotkttkbfm.png" alt="cwc-2019" width="800" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Was this a low (zero) stakes game to hide the fact that we had a gambling problem? Maybe.&lt;/p&gt;

&lt;p&gt;Inspired by the data folks at fivethrityeight, &lt;a href="https://fivethirtyeight.com/methodology/how-our-nfl-predictions-work/"&gt;https://fivethirtyeight.com/methodology/how-our-nfl-predictions-work/&lt;/a&gt; , I wanted to predict world cup match results based on ELO ratings. ELO ratings are widely used in Chess games. It was invented by Arpad Elo, who was a chess player himself and wanted a better way to rate players than the rating system that was prevalent then.&lt;/p&gt;

&lt;p&gt;A player's Elo rating is represented by a number which may change depending on the outcome of rated games played. After every game, the winning player takes points from the losing one. The difference between the ratings of the winner and loser determines the total number of points gained or lost after a game. If the high-rated player wins, then only a few rating points will be taken from the low-rated player. However, if the lower-rated player scores an &lt;a href="https://en.wikipedia.org/wiki/Upset_(competition)"&gt;upset win&lt;/a&gt;, many rating points will be transferred. The lower-rated player will also gain a few points from the higher rated player in the event of a draw. This means that this rating system is self-correcting. Players whose ratings are too low or too high should, in the long run, do better or worse correspondingly than the rating system predicts and thus gain or lose rating points until the ratings reflect their true playing strength.&lt;/p&gt;

&lt;p&gt;Requirements&lt;br&gt;
Scraping Historical Data&lt;br&gt;
A lot of Elo depends on historical matchups between two teams, so it was critical that I had this information.&lt;/p&gt;

&lt;p&gt;Calculating winning %&lt;br&gt;
I wanted to give two teams as input and the program to tell me who has a higher chance of winning based on their elo ratings.&lt;/p&gt;

&lt;p&gt;Scraping Fixtures&lt;br&gt;
As a bonus, I wanted to have the ability to look up fixtures and tell me today’s fixtures, so that I can query the winner between the teams.&lt;/p&gt;

&lt;p&gt;Design Choices&lt;br&gt;
I broke my goal down into three smaller problems&lt;/p&gt;

&lt;p&gt;Interface&lt;br&gt;
I wanted to build a CLI tool, and didn’t want to get my hands dirty with OptionParser class and was looking for an out of the box solution. Thor fit the bill perfectly.&lt;/p&gt;

&lt;p&gt;Fetching / Scraping Data&lt;br&gt;
If you are parsing XML in Ruby, the default choice is Nokogiri, so i didn’t spend much time trying other libraries.&lt;/p&gt;

&lt;p&gt;Calculating Elo&lt;br&gt;
Ruby’s Elo Gem to the rescue. (That was a Ruby pun)&lt;/p&gt;

&lt;p&gt;Note&lt;br&gt;
At this point, there’s an argument to be made that Elo is a rating mechanism and not a means to predict results, which is true. All of this is probably an elaborate ruse to try and make a CLI tool in ruby and do a bit of data scraping and that wouldn’t be far from the truth.&lt;/p&gt;

&lt;p&gt;Fin&lt;br&gt;
Code - &lt;a href="https://github.com/girish-koundinya/Predicta"&gt;https://github.com/girish-koundinya/Predicta&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uMDwW0Vf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kagc5aup1mrmm0kf81sh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uMDwW0Vf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kagc5aup1mrmm0kf81sh.png" alt="predicta-cli" width="800" height="159"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t1x_34AS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sq036y4whedjwauc6ly5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t1x_34AS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sq036y4whedjwauc6ly5.png" alt="predicta-sync" width="800" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Further Reading&lt;br&gt;
Tinder and Elo - &lt;a href="https://twitter.com/iamkoshiek/status/1201111952916975617"&gt;https://twitter.com/iamkoshiek/status/1201111952916975617&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Elo Ratings in Tinder, War of Warcraft - &lt;a href="https://www.theatlantic.com/entertainment/archive/2016/01/how-tinder-matchmaking-is-like-warcraft/424350/"&gt;https://www.theatlantic.com/entertainment/archive/2016/01/how-tinder-matchmaking-is-like-warcraft/424350/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>cricket</category>
      <category>elo</category>
    </item>
    <item>
      <title>Gomobile - Caveat Emptor</title>
      <dc:creator>Girish Koundinya</dc:creator>
      <pubDate>Sun, 31 Jan 2021 05:05:27 +0000</pubDate>
      <link>https://forem.com/_tink3r/gomobile-caveat-emptor-4pb0</link>
      <guid>https://forem.com/_tink3r/gomobile-caveat-emptor-4pb0</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.to/_tink3r/a-three-step-recipe-for-using-gomobile-5096"&gt;My previous post&lt;/a&gt; talks about implementing a simple business logic in Go and integrating it with a mobile application. As an application grows in complexity, there comes a need for a more complex data transfer mechanisms to exist between the app and the library. This post lists a few caveats that one needs to keep in mind while working on Gomobile.&lt;/p&gt;

&lt;h4&gt;
  
  
  Communication between App and Library
&lt;/h4&gt;

&lt;p&gt;Essentially, the communication with Go has to be two way. Communication from Java and Objective-C is via the public header generated by GoMobile and callbacks from Go are implemented using Go Interfaces. GoMobile translates Go interfaces into Protocols in iOS and Interfaces in Java.  We can define a Communication Interface that has two methods onSuccess() and onError(), which will act as our callbacks. We create a class that implements this interface/protocol and pass an instance of this object as a parameter to Go. Go can use this object and callback into the respective platform on completion of the desired action. GoMobile also offers support for the Errors and Exceptions in Objective-C and Java respectively making it very easy to propagate errors from the library.&lt;/p&gt;

&lt;h4&gt;
  
  
  Datatypes
&lt;/h4&gt;

&lt;p&gt;Gomobile has its shortcomings and the most prominent of all, is its restrictive datatype support. Gomobile only allows the use of the following datatypes.&lt;/p&gt;

&lt;h5&gt;
  
  
  Datatypes in Gomobile
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;Signed integer and floating point types.&lt;/li&gt;
&lt;li&gt;String and boolean types.&lt;/li&gt;
&lt;li&gt;Byte slice types. Note the current implementation does not support data mutation of slices passed in as function arguments.&lt;/li&gt;
&lt;li&gt;Any function type all of whose parameters and results have supported types. Functions must return either no results, one result, or two results where the type of the second is the built-in ‘error’ type.&lt;/li&gt;
&lt;li&gt;Any interface type, all of whose exported methods have supported function types.&lt;/li&gt;
&lt;li&gt;Any struct type, all of whose exported methods have supported function types and all of whose exported fields have supported types.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Particularly, the lack of a slice datatype is very inhibiting and as mobile applications tend to deal with collections on a daily basis. There are a few workarounds for this problem.&lt;/p&gt;

&lt;h4&gt;
  
  
  Workarounds
&lt;/h4&gt;

&lt;p&gt;There a few workarounds that can be made so that the data type restcitions doesn't inhibit us from using Gomobile&lt;/p&gt;

&lt;h5&gt;
  
  
  Code generators
&lt;/h5&gt;

&lt;p&gt;One solution is to generate data access methods for a wrapper object around a slice and pass it back and forth between Android/iOS and Go. This solution is presented here - &lt;a href="https://github.com/golang/go/issues/13445#issuecomment-173660985"&gt;https://github.com/golang/go/issues/13445#issuecomment-173660985&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Protocol Buffers
&lt;/h5&gt;

&lt;p&gt;Another solution (which I use currently), is to define protocol buffers as contract objects between Go &amp;lt;&amp;gt; Application. So when Go wants to callback iOS/Android, it converts the complex data type into an array of bytes (which is a supported datatype in Gomobile) and on the application side, it can be converted back into an object. With the help of a few workflow changes, Gomobile can be easily used to pass on complex datatypes to the application.&lt;/p&gt;

&lt;h4&gt;
  
  
  Support for bitcode in iOS
&lt;/h4&gt;

&lt;p&gt;Gomobile does not have support for bitcode that means that bitcode enabled iOS applications will not be able to integrate with Gomobile. That also means that Gomobile cannot be used with platforms like tvOS and watchOS.&lt;/p&gt;

&lt;p&gt;Note - I noticed that this issue is being worked on currently, so hopefully we should have bitcode support soon :)&lt;br&gt;
&lt;a href="https://github.com/golang/go/issues/22395"&gt;https://github.com/golang/go/issues/22395&lt;/a&gt;&lt;/p&gt;



</description>
      <category>mobile</category>
      <category>go</category>
    </item>
    <item>
      <title>A Three Step Recipe for using Gomobile</title>
      <dc:creator>Girish Koundinya</dc:creator>
      <pubDate>Sun, 31 Jan 2021 05:02:05 +0000</pubDate>
      <link>https://forem.com/_tink3r/a-three-step-recipe-for-using-gomobile-5096</link>
      <guid>https://forem.com/_tink3r/a-three-step-recipe-for-using-gomobile-5096</guid>
      <description>&lt;p&gt;This post was originally published in &lt;a href="//blog.koundinya.xyz"&gt;blog.koundinya.xyz&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my earlier &lt;a href="https://dev.to/_tink3r/introduction-to-gomobile-19af"&gt;post&lt;/a&gt;, we saw different ways in which we can use Gomobile. In this post I'll try illustrating how to incorporate Gomobile into a mobile application using the &lt;code&gt;bind&lt;/code&gt; command.&lt;/p&gt;

&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Ensure that you've setup Go and Gomobile in your machine&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install NDK (If you are generating a Android library)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Three Step Recipe
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Step 1 - Write a Go Package
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a go package in &lt;code&gt;$GOPATH/src/github.com/$username/gomobile_contact&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create the following files&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the above linked files I've made a network request, parsed the response and unmarshalled it into a Contact object and returned the first Contact's name. This is an example of a simple business logic component that can be written in Go and ported as a library.&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 2 - Generate libraries
&lt;/h5&gt;

&lt;p&gt;Use the following commands to generate libraries for iOS / Android applications&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    gomobile bind --target=ios #ios
    gomobile bind --target=android #android
```

`


#####  Step 3 - Import library into Application

Gomobile generates a .aar/jar for Android and .Framework for iOS

Import the packages into your application and call the `FetchContactName()` method which returns the first contact's name.

Voilà! You've succesfully generated a library using Go and integrated into your application :)

&amp;lt;br&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>gomobile</category>
      <category>mobile</category>
      <category>go</category>
    </item>
    <item>
      <title>MEET HERMES - MY KINDLE BOT</title>
      <dc:creator>Girish Koundinya</dc:creator>
      <pubDate>Sun, 09 Aug 2020 06:09:29 +0000</pubDate>
      <link>https://forem.com/_tink3r/meet-hermes-my-kindle-bot-730</link>
      <guid>https://forem.com/_tink3r/meet-hermes-my-kindle-bot-730</guid>
      <description>&lt;p&gt;~~~ This post was originally published in my &lt;a href="https://blog.koundinya.xyz/"&gt;blog&lt;/a&gt; ~~~&lt;/p&gt;

&lt;h3&gt;
  
  
  The Nudge
&lt;/h3&gt;

&lt;p&gt;I receive a lot of links on my mobile phone and more often then not, I forget about these links and end up missing content that I was looking forward to reading. I also wanted to make the Kindle as the my primary reading device.&lt;/p&gt;

&lt;p&gt;I was using Pocket to save links and did explore the possibility of using ifttt to send links saved in pocket to my kindle device. It didn't work that well for me :/  there are a few other options &lt;a href="https://help.getpocket.com/article/1127-using-pocket-on-kindle-devices"&gt;https://help.getpocket.com/article/1127-using-pocket-on-kindle-devices&lt;/a&gt;, but they didn't seem very mobile friendly.&lt;/p&gt;

&lt;p&gt;Save to Kindle is the official chrome extension that does a very decent job of sending articles to your kindle, I couldn't find an equivalent mobile app for it.&lt;/p&gt;

&lt;p&gt;I did come across &lt;a href="https://p2k.co/"&gt;https://p2k.co/&lt;/a&gt; and the free plan seemed to fit the bill.&lt;/p&gt;

&lt;p&gt;Oh hell, I think at this point you're probably thinking that i just wanted to build something and was making up reasons for it. You aren't wrong.&lt;/p&gt;

&lt;h3&gt;
  
  
  Architecture
&lt;/h3&gt;

&lt;p&gt;The goal was to have a simple interface to send articles to my kindle and in my head, this how I was thinking about it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fmSssQRO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.koundinya.xyz/images/hermes-initial-arch.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fmSssQRO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.koundinya.xyz/images/hermes-initial-arch.png" alt="Architecture" width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I didn't want to install / build another app and have the hassle of publishing, installing and pushing updates. I wanted to use an existing app and it would be a choice between using Telegram and Whatsapp (apps where sharing was easy). Telegram (at the time of writing ) had a better bot framework and it I could see that there were libraries in multiple languages that supported Telegram.&lt;/p&gt;

&lt;p&gt;While technically not an architectural decision (or is it? &lt;a href="https://martinfowler.com/bliki/TwoHardThings.html"&gt;https://martinfowler.com/bliki/TwoHardThings.html&lt;/a&gt; ), I decided to name the bot Hermes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Uef0jGPB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.koundinya.xyz/images/hermes-wiki.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Uef0jGPB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.koundinya.xyz/images/hermes-wiki.png" alt="Hermes" width="313" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In association with his role as a psychopomp and god who is able to easily cross boundaries, Hermes is prominently worshiped as a messenger, often described as the messenger of the gods (since he can convey messages between the divine realms, the underworld, and the world of mortals).&lt;a href="https://en.wikipedia.org/wiki/Hermes#cite_note-Blackwood-35"&gt;[35]&lt;/a&gt; As a messenger and divine herald, he wears winged sandals (or, in Roman art influenced by Etruscan depictions of &lt;a href="https://en.wikipedia.org/wiki/Turms"&gt;Turms&lt;/a&gt;, a winged cap).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Components
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Communicating with Kindle
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I couldn't find a Kindle API, and the only reliable way to send content to Kindle was by &lt;a href="https://www.amazon.com/gp/sendtokindle/email"&gt;e-mail&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Every kindle account gets a Send-to-Kindle e-mail address. Attachments mailed to this email id, automatically get synced to your kindle.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You have to list the email id from which you'll be sending content in the "Personal Document Settings" section.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Choosing a bot framework
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I came across &lt;a href="https://telegraf.js.org/#/"&gt;https://telegraf.js.org/#/&lt;/a&gt; and the examples and documentation were neat and immediately gave me multiple ideas on how I could structure my app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;While at this point, I hadn't chosen a programming language nor my deployment platform. Telegraf's easy to use API and the fact the deploying a Nodejs app on Heroku is something I've done before, I felt that an express app on Heroku would be the fastest and easiest way to build my bot server.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Setting up a Mailer
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Since the only way to send to Kindle was by Mail. Choosing a mailing service became a critical.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;My only criteria for choosing a mailer was that it should be free. SendGrid's free plan - "&lt;strong&gt;Send 40,000 emails for 30 days, then 100/day forever.&lt;/strong&gt;" was more than adequate for my requirements.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Extracting Article Content
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Not all HTML content can be rendered on the Kindle, and I wanted to ensure that only the text content is sent to kindle and didn't want my device glitching.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I came across - &lt;a href="https://github.com/ndaidong/article-parser"&gt;https://github.com/ndaidong/article-parser&lt;/a&gt; a node package that extracts content from website. It worked beautifully.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/koundinya/hermes"&gt;https://github.com/koundinya/hermes&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Fin
&lt;/h3&gt;

&lt;p&gt;Bot Interface -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Le51WXTD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.koundinya.xyz/images/bot-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Le51WXTD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.koundinya.xyz/images/bot-1.png" alt="bot1" width="800" height="591"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On My Kindle -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ypFXvZUO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.koundinya.xyz/images/kindle-1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ypFXvZUO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.koundinya.xyz/images/kindle-1.jpg" alt="kindle1" width="480" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What happens when ... you run $apt-get install &lt;&gt;</title>
      <dc:creator>Girish Koundinya</dc:creator>
      <pubDate>Sat, 24 Aug 2019 10:59:15 +0000</pubDate>
      <link>https://forem.com/_tink3r/what-happens-when-you-run-apt-get-install-3e41</link>
      <guid>https://forem.com/_tink3r/what-happens-when-you-run-apt-get-install-3e41</guid>
      <description>&lt;p&gt;~~~ This post was originally published in my &lt;a href="https://blog.koundinya.xyz/posts/dependency_tools_apt_get/"&gt;blog&lt;/a&gt; ~~~ &lt;/p&gt;

&lt;p&gt;If you have tried any Linux based system, chances are that you would have run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &amp;lt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;atleast once.&lt;/p&gt;

&lt;p&gt;This would have been followed by you going to have coffee (or tea?) and taking a break while your terminal is spewing stuff like -&lt;/p&gt;

&lt;center&gt;
![Windows-Installation](https://media.giphy.com/media/JmJMzlXOiI0dq/giphy.gif)
&lt;/center&gt;

&lt;blockquote&gt;
&lt;p&gt;I think we need to talk about a few things before we proceed.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I know the gif shows a windows terminal.&lt;/li&gt;
&lt;li&gt;It doesn't show apt-get install.&lt;/li&gt;
&lt;li&gt;I spent a lot of time procastinating and trying to find the perfect gif. It doesn't exist. But a lot of cat gifs were watched during the process.&lt;/li&gt;
&lt;li&gt;You get the idea.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;apt-get is a command line interface for managing packages provided by&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a package
&lt;/h3&gt;

&lt;p&gt;We need step in to a time machine and head back to the age when software was predominantly distributed via mailing lists and FTP. One would have to download the source code, look for a &lt;strong&gt;./configure&lt;/strong&gt; that would&lt;br&gt;
install the required depedencies and then use the &lt;strong&gt;Makefile&lt;/strong&gt; to compile and install the software.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Makes you want to give npm a nice hug and say &lt;strong&gt;"Thank you"&lt;/strong&gt; doesn't it?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This was a cumbersome process to install and play around with software.&lt;br&gt;
Packages were designed to battle this complexity. Packages are prebuilt binaries that one could install using a tool called package manager. The early versions of these package managers only handled the binaries and the dependencies of a binary were not part of the downloaded artifcat. Later versions of package managers included dependency resolution which made it easy and removed the need to lookup depedencies before downloading software. Package management systems usually go hand in hand with a software repository which is a collection of packages or meta infromation about packages. Package managers usually search repositories to find software and their depedencies.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is a Debian Package
&lt;/h3&gt;

&lt;p&gt;Debian GNU/Linux is a particular distribution of the Linux operating system, and numerous packages that run on it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Debian Project was created by Ian Murdock and I love the fact that the project name is a contraction of the names of Debra and Ian Murdock.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With Linux having multiple flavours, each of these distributions have their own sofware repositories, package managers and package structures.&lt;br&gt;
Most notable of these are -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;.deb packages which are used in Ubuntu, Linux Mint and Debian&lt;/li&gt;
&lt;li&gt;.rpm used by RedHat, Fedora and SUSE.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;.deb package mainly contains the following components&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;debian-binary - Contains information regarding version of debian package.&lt;/li&gt;
&lt;li&gt;control archive - This archive contains meta information about the package.&lt;/li&gt;
&lt;li&gt;data archive - Contains the actual software.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  So what is apt-get
&lt;/h3&gt;

&lt;p&gt;The .deb packages were initially managed by a tool called dpkg. dpkg was built to download pre-built binaries and it had capabilities to check if depedenices are matched but did not have the ability to resolve dependencies for the user. Later, a new debian project, Advanced Package Tool (APT) was started which would take care of depedency resolution aswell and works with dpkg.&lt;/p&gt;

&lt;p&gt;APT includes a collection of tools that deal with package management and also command line programs that use the library. apt-get and apt-cache are the most commonly used command line programs. Popularly, apt and the command line tools are reffered to as a front-end to dpkg. i.e means by which users can communicate with dpkg.&lt;/p&gt;

&lt;p&gt;APT uses &lt;em&gt;/etc/apt/sources.list&lt;/em&gt;  as a list of sources from which packages can be downloaded.&lt;br&gt;
An example of a source list is as follows -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;deb http://deb.debian.org/debian buster main
deb-src http://deb.debian.org/debian buster main

deb http://deb.debian.org/debian-security/ buster/updates main
deb-src http://deb.debian.org/debian-security/ buster/updates main

deb http://deb.debian.org/debian buster-updates main
deb-src http://deb.debian.org/debian buster-updates main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can add or remove sources and after modifiying the source list and apt-get is made aware of new locations to search for packages.&lt;/p&gt;

&lt;p&gt;There quite a few front-ends for apt that are avaiable now, some also have a GUI apart from having a command-line interface like Synaptic and aptitude. Historically, apt-get was only designed as a test front-end for libapt-pkg but it was exteremly succesful and popular.&lt;/p&gt;

&lt;center&gt;
![apptitude](https://debian-handbook.info/browse/stable/images/aptitude.png)
&lt;/center&gt;

&lt;center&gt;
![synaptic](https://debian-handbook.info/browse/stable/images/synaptic.png)
&lt;/center&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;When you run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &amp;lt;package-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;apt-get searches for the package in the software repository.&lt;/li&gt;
&lt;li&gt;Checks dependencies.&lt;/li&gt;
&lt;li&gt;Installs dependencies.&lt;/li&gt;
&lt;li&gt;Installs the software package.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A more detailed look into the lookup and dependency resolution process is available here -&lt;br&gt;
&lt;a href="https://debian-handbook.info/browse/stable/sect.apt-get.html"&gt;https://debian-handbook.info/browse/stable/sect.apt-get.html&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://opensource.com/article/18/7/evolution-package-managers"&gt;https://opensource.com/article/18/7/evolution-package-managers&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://blog.tidelift.com/a-brief-history-of-package-management"&gt;https://blog.tidelift.com/a-brief-history-of-package-management&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.debian.org/doc/manuals/debian-faq/ch-pkgtools.en.html"&gt;https://www.debian.org/doc/manuals/debian-faq/ch-pkgtools.en.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Deb_(file_format)"&gt;https://en.wikipedia.org/wiki/Deb_(file_format)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://debian-handbook.info/browse/stable/sect.apt-get.html"&gt;https://debian-handbook.info/browse/stable/sect.apt-get.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Gomobile : Under The Hood</title>
      <dc:creator>Girish Koundinya</dc:creator>
      <pubDate>Sat, 20 Apr 2019 05:17:45 +0000</pubDate>
      <link>https://forem.com/_tink3r/gomobile-under-the-hood-d6p</link>
      <guid>https://forem.com/_tink3r/gomobile-under-the-hood-d6p</guid>
      <description>&lt;p&gt;This post was originally published in my &lt;a href="https://blog.koundinya.xyz/series/gomobile/gomobile_underthehood/"&gt;blog&lt;/a&gt;&lt;/p&gt;

&lt;center&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KLFZx6qZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.koundinya.xyz/images/nathan-van-egmond-1054248-unsplash.jpg" width="800" height="1200"&gt;
&lt;/center&gt;

&lt;center&gt;
Photo by Nathan Van Egmond on Unsplash
&lt;/center&gt;

&lt;p&gt;To understand and fully appreciate what Gomobile does, we’ll need to go through a few concepts (features) related to Java/Objective-C and Go itself and see how Gomobile brings them together. Primarily Java and Objective-C ‘s ability to communicate with c / c ++ and go’s ability to generate c shared libraries.&lt;/p&gt;

&lt;h4&gt;
  
  
  C and C++ support in  Java and Objective-C
&lt;/h4&gt;

&lt;p&gt;Java and Objective-C applications have had the ability to interact with libraries written in c and c ++ for a while. &lt;br&gt;
&lt;br&gt;&lt;br&gt;
Java - &lt;br&gt;
&lt;br&gt;&lt;br&gt;
Communicates with C libraries using JNI framework. Many of the standard library classes depend on JNI to provide functionality to the developer and the user, e.g. file I/O and sound capabilities. Including performance- and platform-sensitive API implementations in the standard library allows all Java applications to access this functionality in a safe and platform-independent manner.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Objective-C - &lt;br&gt;
&lt;br&gt;&lt;br&gt;
Superset of c, and has access to c libraries. &lt;/p&gt;

&lt;h4&gt;
  
  
  Go and CGo
&lt;/h4&gt;

&lt;p&gt;cgo is a library that allows Go programs to interoperate with C libraries. We are interested with a specific feature that cgo provides which allows us to compile Go files into C shared libraries. Go 1.5 introduced execution modes that permits Go methods to be exposed using a C-style api. To read more about execution modes and what their capabilites are - &lt;a href="https://docs.google.com/document/d/1nr-TQHw_er6GOQRsF6T43GGhFDelrAP0NqSS_00RgZQ/edit?pli=1#heading=h.44n2lm20ate5"&gt;https://docs.google.com/document/d/1nr-TQHw_er6GOQRsF6T43GGhFDelrAP0NqSS_00RgZQ/edit?pli=1#heading=h.44n2lm20ate5&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cgo has a few requirements for a Go file to be compiled into a shared library. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The package must be a main package. The compiler will build the package and all of its dependencies into a single shared object binary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The source must import the pseudo-package “C”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the //export comment to annotate functions you wish to make accessible to other languages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An empty main function must be declared.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the following requirements are met then any .go file can be converted into a shared library that contains a .h and a .so file. The .h file contains the exported methods. A in depth example of creating your own .so and .h file is available here - &lt;a href="https://medium.com/learning-the-go-programming-language/calling-go-functions-from-other-languages-4c7d8bcc69bf"&gt;https://medium.com/learning-the-go-programming-language/calling-go-functions-from-other-languages-4c7d8bcc69bf&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  So what does Gomobile do?
&lt;/h4&gt;

&lt;p&gt;We know that -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Java and Objective-C can talk to C&lt;/li&gt;
&lt;li&gt;Using cgo we can make a shared library that can be called by other c files or Java and Objective-C via (1)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;gomobile bind&lt;/code&gt; brings together both of these concepts to generate a library that applications can use to call Go code.&lt;/p&gt;

&lt;p&gt;Example code (Objective-C example) -- &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;If we have a file hello.go -&amp;gt; &lt;br&gt;
&lt;code&gt;package hello&lt;br&gt;
func HelloWorld() {}&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When we run gomobile bind --target=ios, a Hello.framework is created that contains a hello.Objective-C.h and binary called hello. Hello.Objective-C.h is a header file. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now we know that a shared library has been generated and we know that our hello.go does not meet the requirements for a go a file to be converted by cgo. This is where Gomobile comes in, it generates a proxy go file that adheres to cgo requirements and then runs the cgo tool to create a public header and a shared library that can be then be called by Java and Objective-C. So gomobile bind creates a temporary file for hello.go and passes it to cgo to generate a .framework or .aar archives. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  References -
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://medium.com/learning-the-go-programming-language/calling-go-functions-from-other-languages-4c7d8bcc69bf"&gt;https://medium.com/learning-the-go-programming-language/calling-go-functions-from-other-languages-4c7d8bcc69bf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.google.com/document/d/1nr-TQHw_er6GOQRsF6T43GGhFDelrAP0NqSS_00RgZQ/edit?pli=1#"&gt;https://docs.google.com/document/d/1nr-TQHw_er6GOQRsF6T43GGhFDelrAP0NqSS_00RgZQ/edit?pli=1#&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.google.com/document/d/1y9hStonl9wpj-5VM-xWrSTuEJFUAxGOXOhxvAs7GZHE/edit"&gt;https://docs.google.com/document/d/1y9hStonl9wpj-5VM-xWrSTuEJFUAxGOXOhxvAs7GZHE/edit&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>gomobile</category>
      <category>mobile</category>
      <category>go</category>
    </item>
    <item>
      <title>Introduction to Gomobile</title>
      <dc:creator>Girish Koundinya</dc:creator>
      <pubDate>Thu, 18 Apr 2019 17:24:33 +0000</pubDate>
      <link>https://forem.com/_tink3r/introduction-to-gomobile-19af</link>
      <guid>https://forem.com/_tink3r/introduction-to-gomobile-19af</guid>
      <description>&lt;p&gt;This post was originally published in &lt;a href="//blog.koundinya.xyz"&gt;blog.koundinya.xyz&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When someone reads about the Go programming language, they would probably come across Rob Pike’s famous 'Concurrency Is Not Parallelism' talk or they might discover that Docker and Kubernetes and many other cloud infra tools have been written in Go (Go has been dubbed 'The Language of the Cloud'). I want to write about one of Go's lesser known tool in the box - Gomobile. Gomobile is a mobile application development tool written in Go, built with the aim of developing cross-platform applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why would you try Gomobile?
&lt;/h3&gt;

&lt;p&gt;I can hear your collective groan, 'Not another Cross Platform Mobile Development Solution'. And I agree, and infact I would want to lend my voice to it. Sometimes the benefit of having a single codebase pales in comparison to the sub par experience provided by cross platform frameworks.&lt;/p&gt;

&lt;p&gt;So why are we talking about Gomobile then?&lt;/p&gt;

&lt;p&gt;Gomobile provides two strategies for development&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;To develop an entire mobile application using -&lt;br&gt;
&lt;code&gt;gomobile build&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To develop a library that can be used by mobile applications using -&lt;br&gt;
&lt;code&gt;gomobile bind&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Using Gomobile as a generator for SDKs that can be plugged into applications is very similar to how companies are Google and Dropbox are approaching cross-platform development. &lt;a href="https://arstechnica.com/information-technology/2014/11/how-google-inbox-shares-70-of-its-code-across-android-ios-and-the-web/"&gt;Google used J2OBJC in Inbox&lt;/a&gt;&lt;br&gt;
and Dropbox has &lt;a href="https://www.youtube.com/watch?v=ssqhz_1pPI4"&gt;Djinni&lt;/a&gt;. &lt;br&gt;
&lt;code&gt;gomobile bind&lt;/code&gt; is an option if your application has a lot of business logic that you don't want to rewrite in multiple platforms.&lt;/p&gt;

&lt;h3&gt;
  
  
  Gomobile bind
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;gomobile bind&lt;/code&gt; generates language bindings for Java and Objective-C. A simple pattern for developing mobile applications using bind would be develop the view layer in the native language and then communicate with the generated sdk to obtain model objects.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mobile App Architecture
&lt;/h4&gt;

&lt;p&gt;There are quite a few mobile application architecture patterns in Android and iOS like MVC, MVP, MVVM, and VIPER. All of these architectural designs can be broadly represented by three layers.&lt;/p&gt;

&lt;center&gt;![Mobile App Architecture](https://blog.koundinya.xyz/images/mobile+arch.png)&lt;/center&gt;

&lt;h5&gt;
  
  
  View Layer
&lt;/h5&gt;

&lt;p&gt;This layer is responsible for user interaction and rendering of data. Activity and ViewController classes in Android and iOS respectively are types of classes that are normally associated with this layer.&lt;/p&gt;

&lt;h5&gt;
  
  
  Business Logic Layer
&lt;/h5&gt;

&lt;p&gt;This layer contains the core application logic. The interactions from the view are sent to this layer, which is processed and used to make calls to the data layer.&lt;/p&gt;

&lt;h5&gt;
  
  
  Data Layer
&lt;/h5&gt;

&lt;p&gt;The data layer controls all of the data access operations. This can be anything from accessing a local SQLite database to interacting with the network.&lt;/p&gt;

&lt;center&gt;![Mobile App Architecture With Gomobile](https://blog.koundinya.xyz/images/mobile+go+arch.png)&lt;/center&gt;

&lt;p&gt;With &lt;code&gt;gomobile bind&lt;/code&gt;, the business logic and data layers can be moved to Go and shared between iOS and Android applications. This way business logic needs to be written only once and the data access protocols are similar between operating systems. You also don’t lose out on the user experience which is a common drawback in most cross platform solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;Here are some references that you might find interesting to get started with Gomobile&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://godoc.org/golang.org/x/mobile/cmd/gomobile"&gt;https://godoc.org/golang.org/x/mobile/cmd/gomobile&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ZLq0Zeoyu6Y"&gt;https://www.youtube.com/watch?v=ZLq0Zeoyu6Y&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@matryer/tutorial-calling-go-code-from-swift-on-ios-and-vice-versa-with-gomobile-7925620c17a4"&gt;https://medium.com/@matryer/tutorial-calling-go-code-from-swift-on-ios-and-vice-versa-with-gomobile-7925620c17a4&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@rakyll/calling-go-from-swift-be88709942c3"&gt;https://medium.com/@rakyll/calling-go-from-swift-be88709942c3&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>gomobile</category>
      <category>mobile</category>
      <category>go</category>
    </item>
  </channel>
</rss>
