<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mohammed Irshad on Medium]]></title>
        <description><![CDATA[Stories by Mohammed Irshad on Medium]]></description>
        <link>https://medium.com/@irshadhasmat?source=rss-4e0a67360790------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*k44aDXcQtrnoEGT53qAlyw.png</url>
            <title>Stories by Mohammed Irshad on Medium</title>
            <link>https://medium.com/@irshadhasmat?source=rss-4e0a67360790------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:27:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@irshadhasmat/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[GoLang: Simple PUB/SUB implementation using REDIS]]></title>
            <link>https://irshadhasmat.medium.com/golang-simple-pub-sub-implementation-using-redis-b57070476d45?source=rss-4e0a67360790------2</link>
            <guid isPermaLink="false">https://medium.com/p/b57070476d45</guid>
            <category><![CDATA[realtime]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[pub-sub]]></category>
            <category><![CDATA[redis]]></category>
            <dc:creator><![CDATA[Mohammed Irshad]]></dc:creator>
            <pubDate>Mon, 23 Nov 2020 06:23:36 GMT</pubDate>
            <atom:updated>2020-11-23T06:23:36.353Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Redis Pub Sub Implementation using GoLang" src="https://cdn-images-1.medium.com/max/1024/1*CH95OHk2mZpGM2gvuN-vqA.png" /></figure><p>PUB/SUB is an important concept when we want to alert all the connected application(Subscriber) in case of any event where Publisher emits the message to them.</p><h4>To test the pub/sub using REDIS use below command</h4><p>Make sure that you have REDIS installed in our system/server where you want to connect. Enter below command to connect to REDIS command line interface on multiple terminal so that one can act as subscriber and other can act as publisher.</p><pre>redis-cli</pre><blockquote>To Publish the message the on a Channel</blockquote><pre><strong>PUBLISH example test</strong></pre><pre><strong>Explanation:</strong><br>example : it is a channel where we want to publish the message<br>test : is the message which we want to publish through the channel</pre><blockquote>To Subscribe the message from the Channel</blockquote><pre><strong>SUBSCRIBE example</strong></pre><pre><strong>Explanation:</strong><br>example : it is a channel where we want to publish the message</pre><h4>Step 1: Importing the Library</h4><pre>import &quot;github.com/gomodule/redigo/redis&quot;</pre><h4>Step 2: Establishing the Connection</h4><pre>c, err := redis.Dial(&quot;tcp&quot;, &quot;localhost:6379&quot;)<br>if err != nil {<br>    log.Println(err)<br>}</pre><h4>Step 3: Publish the message</h4><pre>c.Do(&quot;PUBLISH&quot;, &quot;example&quot;, &quot;hello &quot;+time.Now().String())</pre><h4>Step 4: Subscribe the message</h4><pre>psc := redis.PubSubConn{Conn: c}<br>psc.Subscribe(&quot;example&quot;)<br>for {<br> switch v := psc.Receive().(type) {<br> case redis.Message:<br>  fmt.Printf(&quot;%s: message: %s\n&quot;, v.Channel, v.Data)<br> case redis.Subscription:<br>  fmt.Printf(&quot;%s: %s %d\n&quot;, v.Channel, v.Kind, v.Count)<br> case error:<br>  fmt.Println(v)<br> }<br>}</pre><p>Working Code for PUB/SUB</p><p><a href="https://gist.github.com/irshadhasmat/abdd99a0126c1971a6bbe3b68a9f37ef">https://gist.github.com/irshadhasmat/abdd99a0126c1971a6bbe3b68a9f37ef</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b57070476d45" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GoLang : Simple JSON Parsing using empty Interface and without Struct in Go Language]]></title>
            <link>https://irshadhasmat.medium.com/golang-simple-json-parsing-using-empty-interface-and-without-struct-in-go-language-e56d0e69968?source=rss-4e0a67360790------2</link>
            <guid isPermaLink="false">https://medium.com/p/e56d0e69968</guid>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[empty-interface]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[parsing]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Mohammed Irshad]]></dc:creator>
            <pubDate>Sat, 19 Jan 2019 09:55:40 GMT</pubDate>
            <atom:updated>2020-03-03T07:13:45.486Z</atom:updated>
            <content:encoded><![CDATA[<h3>GoLang : Dynamic JSON Parsing using empty Interface and without Struct in Go Language</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LUYjHDpakMSOhp3sV0qMTg.png" /></figure><p><strong>JSON</strong>(JavaScript Object Notation) parsing a day to activity for a developer. Most of the API which developer parse are in JSON.</p><p>Here we will see how we can parse JSON Object and Array using GoLang Interfaces. This reduce overhead to creating struct when data is unstructured and we can simply parse the data and get the desire value from the JSON.</p><p>This article will explain parsing different type of JSON.</p><ol><li>Simple object JSON</li><li>Simple array JSON</li><li>Embedded object in JSON</li><li>Embedded object in array of JSON</li></ol><p>My strategy would be learn by doing!!! writing the code first and providing the explanation always works for me.</p><h3>1. Parsing Simple object JSON:</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9b077cad944de9ef4a2a6b4ea1d9677/href">https://medium.com/media/d9b077cad944de9ef4a2a6b4ea1d9677/href</a></iframe><pre><strong>Output:</strong><br>Id : 11<br>Name : Irshad<br>Department : IT<br>Designation : Product Manager</pre><p>Try it at : <a href="https://play.golang.org/p/JlSoK1t1CkO">https://play.golang.org/p/JlSoK1t1CkO</a></p><pre><strong>Code Explanation:</strong></pre><pre>/* <strong>First:</strong> declared map of string with empty interface <br>which will hold the value of the parsed json. */<br><strong>var result map[string]interface{}</strong></pre><pre>/* <strong>Second:</strong> Unmarshal the json string string by converting <br>it to byte into map */<br><strong>json.Unmarshal([]byte(empJson), &amp;result)</strong></pre><pre>/* <strong>Third:</strong> Read the Value by its key */<br><strong>fmt.Println(&quot;Id :&quot;, result[&quot;id&quot;])</strong></pre><h3>2. Parsing Simple Array JSON:</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8b9695e2056ee6db57d610ffac622d3/href">https://medium.com/media/a8b9695e2056ee6db57d610ffac622d3/href</a></iframe><pre><strong>Output:</strong><br>Reading Value for Key : 0<br>Id : 1 - Name : Mr. Boss - Department :  - Designation : Director<br>Reading Value for Key : 1<br>Id : 11 - Name : Irshad - Department : IT - Designation : Product Manager<br>Reading Value for Key : 2<br>Id : 12 - Name : Pankaj - Department : IT - Designation : Team Lead</pre><p>Try it at : <a href="https://play.golang.org/p/A9Nr4TZqtgB">https://play.golang.org/p/A9Nr4TZqtgB</a></p><pre><strong>Code Explanation:</strong></pre><pre>/* <strong>First:</strong> declared array map of string with empty interface <br>which will hold the value of the parsed json. */<br><strong>var results []map[string]interface{}</strong></pre><pre>/* <strong>Second:</strong> Unmarshal the json string string by converting <br>it to byte into map */<br><strong>json.Unmarshal([]byte(empArray), &amp;results)</strong></pre><pre>/* <strong>Third:</strong> Read the each item from an array of map using range */<br><strong>for key, result := range results {}</strong></pre><pre>/* <strong>Fourth:</strong> Read the Value by its key inside range loop */<br><strong>fmt.Println(&quot;Id :&quot;, result[&quot;id&quot;])</strong></pre><h3>3. Parsing Embedded object in JSON</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ee5f0df6a910fa40c0a2b30561d456e/href">https://medium.com/media/5ee5f0df6a910fa40c0a2b30561d456e/href</a></iframe><pre><strong>Output:</strong><br>Id : 11<br>Name : Irshad<br>Department : IT<br>Designation : Product Manager<br>Address : Mumbai Maharashtra India</pre><p>Try it at : <a href="https://play.golang.org/p/X4Z9CPwG5JL">https://play.golang.org/p/X4Z9CPwG5JL</a></p><pre><strong>Code Explanation:</strong></pre><pre>/* <strong>First:</strong> declared map of string with empty interface <br>which will hold the value of the parsed json. */<br><strong>var result map[string]interface{}</strong></pre><pre>/* <strong>Second:</strong> Unmarshal the json string string by converting <br>it to byte into map */<br><strong>json.Unmarshal([]byte(empJson), &amp;result)</strong></pre><pre>/* <strong>Third:</strong> To Read data from address node we have to again declare one more map with empty interface */<br><strong>address := result[&quot;address&quot;].(map[string]interface{})</strong></pre><pre>/* <strong>Fourth:</strong> Read the Value from main node */<br><strong>fmt.Println(&quot;Id :&quot;, result[&quot;id&quot;])</strong></pre><pre>/* <strong>Fifth:</strong> Read the Value from address node */<br><strong>fmt.Println(&quot;City :&quot;, address[&quot;city&quot;])</strong></pre><h3>4. Parsing Embedded object in Array of JSON</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc204a6325061a7131deefba648cba5f/href">https://medium.com/media/bc204a6325061a7131deefba648cba5f/href</a></iframe><pre><strong>Output:<br></strong>Reading Value for Key : 0<br>Id : 1 - Name : Mr. Boss - Department :  - Designation : Director<br>Address : Mumbai Maharashtra India<br>Reading Value for Key : 1<br>Id : 11 - Name : Irshad - Department : IT - Designation : Product Manager<br>Address : Mumbai Maharashtra India<br>Reading Value for Key : 2<br>Id : 12 - Name : Pankaj - Department : IT - Designation : Team Lead<br>Address : Pune Maharashtra India</pre><p>Try it at : <a href="https://play.golang.org/p/P54UcFy4uJt">https://play.golang.org/p/P54UcFy4uJt</a></p><pre><strong>Code Explanation:</strong></pre><pre>/* <strong>First:</strong> declared array map of string with empty interface <br>which will hold the value of the parsed json. */<br><strong>var results []map[string]interface{}</strong></pre><pre>/* <strong>Second:</strong> Unmarshal the json string string by converting <br>it to byte into map */<br><strong>json.Unmarshal([]byte(empArray), &amp;results)</strong></pre><pre>/* <strong>Third:</strong> Read the each item from an array of map using range */<br><strong>for key, result := range results {}</strong></pre><pre>/* <strong>Fourth:</strong> To Read data from address node from each item we have to declare one more map with empty interface inside range loop */<br><strong>address := result[&quot;address&quot;].(map[string]interface{})</strong></pre><pre>/* <strong>Fifth:</strong> Read the result value by its key inside range loop */<br><strong>fmt.Println(&quot;Id :&quot;, result[&quot;id&quot;])</strong></pre><pre>/* <strong>Sixth:</strong> Read the address value by its key inside range loop */<br><strong>fmt.Println(&quot;City :&quot;, address[&quot;city&quot;])</strong></pre><p>Parsing JSON in go is very each and its depends upon developer preferences whether they want to use struct or they want to parse them raw using interfaces.</p><p>Will keep posting new articles! Thank you!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e56d0e69968" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GoLang : Getting started with CockroachDB and Go Language]]></title>
            <link>https://irshadhasmat.medium.com/golang-getting-started-with-cockroachdb-with-go-language-21c67ab569b0?source=rss-4e0a67360790------2</link>
            <guid isPermaLink="false">https://medium.com/p/21c67ab569b0</guid>
            <category><![CDATA[cockroachdb]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[crud]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Mohammed Irshad]]></dc:creator>
            <pubDate>Thu, 31 May 2018 15:41:03 GMT</pubDate>
            <atom:updated>2018-05-31T16:10:48.477Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*JZQlopJ6mtD2yLjaPCgcxQ.png" /></figure><p>From last few months I have been working with CockroachDB. And after diving deeper into the philosophy of cockroach I started loving it. Reason for choosing CockroachDB are:</p><ul><li><strong>Open Source</strong></li><li><strong>JSON Support</strong></li><li><strong>High Availability</strong></li><li><strong>Strongly Consistent Replication</strong></li><li><strong>Ease of use</strong></li></ul><p>This tutorial will cover below topics:</p><ol><li>Installing &amp; Running CockroachDB</li><li>Creating Database and Table in CockroachDB</li><li>Installing CockroachDB Go <strong>pq</strong> library</li><li>Connection to DB</li><li>SQL Statement</li><li>Full Source Code</li></ol><h3>1. Installing &amp; Running CockroachDB</h3><p>I am using MAC, so I would be showing the steps for mac for other OS you can use below URL to install CockroachDB.</p><p><a href="https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html">Install CockroachDB | CockroachDB Docs</a></p><pre>brew install cockroach</pre><p>Once the CockroachDB has been installed its time to start CockroachDB, Here I would be using single node server for ease of use.</p><p>Command to start CockroachDB with in a insecure mode</p><pre>cockroach start --insecure</pre><p>You can follow the below link to start the CockroachDB on your OS.</p><p><a href="https://www.cockroachlabs.com/docs/stable/start-a-local-cluster.html">Start a Local Cluster (Insecure)</a></p><p>Once cockroach start successfully you can see following message printed on your console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*KE2D1gENyN4igraDn00JiA.png" /></figure><p>If you see the following message.</p><p>Congratulations!!! You have successfully installed and started CockroachDB.</p><h3>2. Creating Database and Table in CockroachDB</h3><p>We would be creating a simple database called <strong><em>“company_db”</em></strong> with table <strong><em>“tbl_employee”</em></strong></p><p>You can now connect to CockroachDB SQL Client in a insecure mode using below command to execute the SQL statement.</p><pre>cockroach sql --insecure</pre><p>To create Database and to set database for current session use below SQL statement</p><pre>create database company_db;<br>set database = company_db;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*DblMCx2Ew79WcC9hHY1lMw.png" /></figure><p>Create Table using below Create table Statement</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be094d8ac1cf1a28db3ebdddc9dd771a/href">https://medium.com/media/be094d8ac1cf1a28db3ebdddc9dd771a/href</a></iframe><h3>3. Installing CockroachDB Go pq library</h3><p>CockroachDB uses Postgres database protocol so we have use <a href="https://godoc.org/github.com/lib/pq">Go pq driver</a>. To install Go pg driver, run the following command:</p><pre>go get -u github.com/lib/pq</pre><blockquote>Note: Make sure that you have GO installed and GOPATH and GOBIN are set in environment variable.</blockquote><h3>4. Connection to DB</h3><pre>// Connect to the &quot;company_db&quot; database.<br>db, err := sql.Open(&quot;postgres&quot;,&quot;postgresql://root@localhost:26257/company_db?sslmode=disable&quot;)</pre><h3>5. SQL Statement</h3><p><strong>Insert, Update and Delete</strong> can use the same function db.Exec()</p><pre>//Inserting a Row in to DB.<br>_, err := db.Exec(`INSERT INTO tbl_employee (full_name, department, designation, created_at, updated_at) VALUES (&#39;Irshad&#39;, &#39;IT&#39;, &#39;Product Manager&#39;, NOW(), NOW());`);</pre><p><strong>Select</strong> Statement uses db.Query</p><pre>//Select statement<br>rows, err := db.Query(&quot;select employee_id, full_name FROM tbl_employee;&quot;)</pre><h3>6. Full Source Code</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f305b8b7a152c9fe65596bc6e95f9a2a/href">https://medium.com/media/f305b8b7a152c9fe65596bc6e95f9a2a/href</a></iframe><p>Run the above code and if run successfully it will print the data in the console if not error message would get printed.</p><p>To verify the data you can run below statement in CockroachDB SQL Client:</p><pre>select * from tbl_employee;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fYExy2lhqDwMd7CpKbiAsA.png" /></figure><p>As you can see its very easy to start working with CockroachDB in GoLang.<br>Kindly comment if you have any doubt. I would love to help.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21c67ab569b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GoLang : String to Int & Int64 Conversion and Int & int64 to String Conversion in Go Language]]></title>
            <link>https://irshadhasmat.medium.com/golang-string-to-int-int64-conversion-and-int-int64-to-string-conversion-774f9f23cb03?source=rss-4e0a67360790------2</link>
            <guid isPermaLink="false">https://medium.com/p/774f9f23cb03</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[data-type]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[int64]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <dc:creator><![CDATA[Mohammed Irshad]]></dc:creator>
            <pubDate>Tue, 29 May 2018 18:08:51 GMT</pubDate>
            <atom:updated>2018-06-15T05:21:54.868Z</atom:updated>
            <content:encoded><![CDATA[<h3>GoLang : String to Int &amp; Int64 Conversion and Int &amp; int64 to String Conversion</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*_d8_TuE2kIsZnCSEamV4jA.jpeg" /></figure><p>Conversion of datatype is a normal task of every developer. So, here I would be giving you a snippet of how to convert <strong>string</strong> to <strong>int</strong> and <strong>int64 </strong>and vice versa<strong>.</strong></p><h3>String to Int Conversion:</h3><p>String to Int conversation =&gt; strconv.Atoi function return integer with error if any.</p><p>Atoi means “A” String to “i” integer</p><pre>str := &quot;12345&quot;</pre><pre>intI, err := strconv.Atoi(str)</pre><p>Full Script :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b246685710b230e9ba0ef622bfadeafc/href">https://medium.com/media/b246685710b230e9ba0ef622bfadeafc/href</a></iframe><p>Golang Playground : <a href="https://play.golang.org/p/obJKzJJXSpP">https://play.golang.org/p/obJKzJJXSpP</a></p><h3>String to Int64 Conversion:</h3><p>String to Int64 conversation =&gt; strconv.ParseInt function return int64 with error if any.</p><p>strconv.ParseInt() =&gt; function convert string to int64</p><pre>str := &quot;12345&quot;</pre><pre>int64I, err := strconv.ParseInt(str, 10, 64)</pre><p>Full Script :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36f6cc90ca32fef111460c5320d5d032/href">https://medium.com/media/36f6cc90ca32fef111460c5320d5d032/href</a></iframe><p>Golang Playground : <a href="https://play.golang.org/p/DQGJga3Rb8m">https://play.golang.org/p/DQGJga3Rb8m</a></p><h3>Int &amp; Int64 to String Conversion:</h3><p>To convert Int to String we have to use strconv.Itoa(int) function.</p><p>To convert Int64 to String we have to use strconv.FormatInt(int64, 10) function.</p><pre>var i int = 12345<br>var i64 int64 = 12345</pre><pre>// Conversion of Int to String<br>strInt := strconv.Itoa(i)<br> <br>// Conversion of Int64 to String<br>strInt64 := strconv.FormatInt(i64, 10)</pre><p>Full Script :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff6eded8ca9d4e97e76592057afd0640/href">https://medium.com/media/ff6eded8ca9d4e97e76592057afd0640/href</a></iframe><p>Golang Playground : <a href="https://play.golang.org/p/k1AHCHGVi7w">https://play.golang.org/p/k1AHCHGVi7w</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=774f9f23cb03" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>