<?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 Arief Darmawan on Medium]]></title>
        <description><![CDATA[Stories by Arief Darmawan on Medium]]></description>
        <link>https://medium.com/@ariefdarmawan_59107?source=rss-ee0e245789aa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*OiTrExTTHer-F9HT.</url>
            <title>Stories by Arief Darmawan on Medium</title>
            <link>https://medium.com/@ariefdarmawan_59107?source=rss-ee0e245789aa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 04:49:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ariefdarmawan_59107/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[Membuat Servis Aplikasi (Go Based) Kita Immortal]]></title>
            <link>https://medium.com/kanoteknologi/membuat-servis-aplikasi-go-based-kita-immortal-a66f276bdac3?source=rss-ee0e245789aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/a66f276bdac3</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[immortality]]></category>
            <dc:creator><![CDATA[Arief Darmawan]]></dc:creator>
            <pubDate>Mon, 12 Nov 2018 23:57:27 GMT</pubDate>
            <atom:updated>2018-11-12T23:59:18.367Z</atom:updated>
            <content:encoded><![CDATA[<p>Dalam dunia fiksi, immortal adalah sebutan untuk mereka yang ndak bisa mati, dibacok lah, dibom lah, di-nuke sekalian, ehhh dia masih bisa bertahan hidup. Tokoh seperti <em>Wolverine, Deadpool</em>, dan <em>semua komunitas Highlander </em>adalah representasi dari <em>immortal</em> being yang ndak bisa mati … kecuali dengan peraturan tertentu. Menjadi immortal bagi para superhero itu ada pro dan kontranya. Tapi bagi sebuah aplikasi, menjadi immortal lebih banyak pro-nya.</p><p><em>Reliability / kehandalan </em>adalah salah satu kunci utama untuk menyatakan sebuah servis layak berada di fase produksi atau tidak. Dan tolak ukur dari reliability ini adalah <em>downtime </em>atau lama waktu servis kita tidak menyala pada kurun waktu tertentu.</p><p>Downtime sendiri sebenarnya terbagi menjadi dua macam downtime. <strong><em>Expected downtime</em></strong>, adalah downtime yang memang kita harapkan, downtime ini terjadi karena memang kita sengaja mematikan servis untuk keperluan tertentu, misal: upgrade binary, merubah konfigurasi dan memerlukan restart servis, dan sejenisnya. <strong><em>Unexpected downtime</em></strong>, adalah jenis downtime kedua yang akan menjadi mimpi buruk para DevOps dan Sysadmin karena downtime ini adalah downtime yang tidak diharapkan. Downtime ini umumnya terjadi karena hal-hal yang pelik yang ujung pangkalnya mungkin memerlukan penelitian lebih dalam.</p><p>Pada kesempatan kali ini, kita akan coba membuat sebuah konsep <strong><em>immortal </em></strong>application dengan menggunakan bahasa pemrograman Go</p><h3>Use case — sebuah aplikasi yang error-potential-free</h3><p>Well, jujur sih ndak akan ada aplikasi yang error-potential-free, karena biarpun sebagus apapun coding kita, banyak hal-hal lain diluaran sana yang akan berpengaruh ke reliability aplikasi kita. Jaringan tiba2 mati lah, database kehabisan storage lha, dan lain-lain.</p><p>Go sendiri sebagai bahasa, cukup bijak dengan membuat error sebagai sebuah object dan membuat guideline untuk mengembalikan nilai error ini pada fungsi-fungsi yang kita yakini berpotensi memiliki error</p><p>Coba lihat kode ini</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2594c3fa9855ab95a668aebb903cb032/href">https://medium.com/media/2594c3fa9855ab95a668aebb903cb032/href</a></iframe><p>Kode di atas adalah simple code yang akan terus menangkap value dari standard input untuk kemudian dilakukan banyak pengecekan apakah value tersebut adalah integer. Apabila iya, kuadrat value dari nilai tersebut akan disebutkan. Dan apabila ada kesalahan, sekian banyak error handling akan menangani error tersebut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJzKkro0q6Il7zPNs5cyWw.png" /><figcaption>Base case, sebuah aplikasi yang error-potency-free</figcaption></figure><p>So far, so good … tapi <em>real life challenge </em>tidak seindah dan semudah tutorial di internet. Seperti diatas, banyak hal yang bisa menyebabkan panic error dikirim oleh aplikasi kita dan berujung pada <em>tewasnya</em> aplikasi kita … <em>an unexpected shutdown</em></p><h3>Unexpected Shutdown</h3><p>Coba kita tambahkan sedikit baris pada code kita diatas, untuk mensimulasikan panic shutdown</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a88e9a56e6b401a36af74423cf62506f/href">https://medium.com/media/a88e9a56e6b401a36af74423cf62506f/href</a></iframe><p>Pada line 27–29 di atas, kita tambahkan beberapa line yang akan mengembalikan panic error apabila nilai yang dimasukan adalah antara 10 50. Well, tentu saja kita dengan mudah bisa membuat <em>error trap</em> disini, tapi misalkan ini adalah panic error yang akan dimunculkan oleh banyak hal yang mungkin tidak kita antisipasi sebelumnya, <em>and trust me</em>, banyak banget hal-hal kecil yang memungkinkan ini terjadi: <em>interface{} handling, array index, object yang belum dicreate di sebuah fungsi, jaringan yang tiba-tiba koit, database lock, open file limit yang kekecilan </em>dan aneka hal-hal lain. Jadi intinya panic error sangat mungkin terjadi</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4aAG6K6Xi9EvzBRNGf6n5A.png" /><figcaption>Panic error terjadi</figcaption></figure><h3>Mengenali Panic Error</h3><p>Panic error terjadi karena ada sebuah kesalahan yang terjadi dan bersumber dari proses yang tidak diantisipasi untuk menimbulkan kesalahan, sehingga tidak ada error trapping disana. Panic error secara otomatis akan memberhentikan semua thread, termasuk thread utama. Konsekuensinya aplikasi kita akan mengalami shutdown dan sebuah <em>unexpected downtime</em> terjadi</p><p>Di bahasa Go, ada perintah recover yang difungsikan untuk mengantisipasi panik, tapi perintah ini hanya difungsikan untuk mengidentifikasi apabila panic terjadi atau tidak, dan mengisolate akibat dari panic hanya pada thread yang bersangkutan.</p><p><em>Gotcha, we got a hint</em></p><p>Dengan memanfaatkan karakteristik recover kita bisa membuat karakteristik aplikasi kita menjadi immortal</p><blockquote>Untuk membuat aplikasi kita bersifat immortal, pastikan tidak ada potensi error di main thread, dan letakan process utama di thread lain dan antisipasi panic di thread tersebut dengan perintah recover</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/920b943f9ea5dc01a55f1cf56548da2e/href">https://medium.com/media/920b943f9ea5dc01a55f1cf56548da2e/href</a></iframe><p>Pada kode diatas, proses utama saya masukan sebagai go-routine baru sehingga proses tersebut akan dijalankan pada thread yang berbeda daripada main thread. Juga recover digunakan untuk mengantisipasi dan mengisolatepanic yang akan terjadi pada thread tersebut</p><p>Terus apa gunanya main thread dong? main thread bisa digunakan untuk:</p><ol><li>Melakukan persiapan sebelum proses utama dijalankan <em>(pastikan error free)</em></li><li>Melakukan monitoring terhadap proses utama</li><li>Melayani proses <em>expected shutdown</em>, karena untuk beberapa hal, kita perlu memberhentikan aplikasi kita. Expected shutdown ini bisa dilihat pada kode diatas line 48, 51–48, dan 58–66</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_3sBnRXAzagBJgvqyBzVTg.png" /><figcaption>recover mengantisipasi panic di thread lain</figcaption></figure><p>Bisa dilihat, ketika panic terjadi, aplikasi tidak berhenti karena panic terjadi pada thread lain dan diisolasi oleh recover. Main thread tetap aman</p><p>Tapi heyyy, muncul persoalan lain, <strong><em>proses utama berhenti</em>, </strong>jadi istilahnya aplikasi kita mati segan hidup tak mau, karena sekalipun tidak <em>shutdown </em>tapi proses utamanya tidak berjalan.</p><blockquote>Untuk membuat aplikasi kita bersifat immortal, self start servis utama harus dilakukan ketika panic terjadi</blockquote><p>Nah bagaimana melakukan proses <strong><em>self start</em></strong> ini. Sederhana saja, cukup buat sebuah wrapper yang berfungsi untuk melakukan: <strong><em>1. Panic handling dengan recover, 2. Mengaktifkan proses utama</em></strong></p><p>Secara sederhana kode wrapper ini adalah sebagai berikut</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff41d2cb56ae5c8edf10c6ba27246469/href">https://medium.com/media/ff41d2cb56ae5c8edf10c6ba27246469/href</a></iframe><p>Oke, mari kita lihat hasilnya …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nWO5g3U5fGIpXYYADLWVrQ.png" /><figcaption>Sebuah aplikasi yang bersifat immortal</figcaption></figure><p>So, that’s it … how to make an immortal application or service using Go</p><p>Kode lengkapnya dibawah ini</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2714ecf7c71b6fa26721ed547c486ee4/href">https://medium.com/media/2714ecf7c71b6fa26721ed547c486ee4/href</a></iframe><p>Semoga bisa menambah khasanah pengetahuan dalam menciptakan solusi digital yang lebih berkualitas</p><p>Happy coding !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a66f276bdac3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kanoteknologi/membuat-servis-aplikasi-go-based-kita-immortal-a66f276bdac3">Membuat Servis Aplikasi (Go Based) Kita Immortal</a> was originally published in <a href="https://medium.com/kanoteknologi">KANO Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to do web directory reverse proxy on Go ?]]></title>
            <link>https://medium.com/kanoteknologi/how-to-do-web-directory-reverse-proxy-on-go-ef7bacb11c8d?source=rss-ee0e245789aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef7bacb11c8d</guid>
            <category><![CDATA[reverse-proxy]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Arief Darmawan]]></dc:creator>
            <pubDate>Sun, 04 Nov 2018 19:26:48 GMT</pubDate>
            <atom:updated>2018-11-04T20:15:20.992Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to do web directory reverse proxy on Go ?</h3><p>Before we going further, lets discuss about what is reverse proxy. <em>Reverse Proxy is a server process to retrieves resources on behalf of client request from one or more servers. These resources then returned to client, appearing as they originating from the proxy itself. </em>The definition sounds smart heh, that is because I copied from this <a href="https://en.wikipedia.org/wiki/Reverse_proxy">wikipedia</a> link :)</p><p>Lets do some image to make it more crystal clear about this reverse proxy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*ufiUqhytBYJ8BsKxnMLX3g.png" /><figcaption>Reverse proxy diagram (taken from <a href="https://kemptechnologies.com/reverse-proxy/reverse-proxy/">https://kemptechnologies.com/reverse-proxy/reverse-proxy/</a>)</figcaption></figure><p>So as you may see, user will send a request to reverse proxy server. Server then will re-send this request to respective application to obtain response/resources and send back this response to user appearing as it is originated from reverse proxy server</p><h3>Why we have to do reverse proxy ?</h3><p>Well, this reverse proxy can be used for many case. We will discuss that part on end of topic, but for now, I will give a simple use case why on earth we need this reverse proxy</p><p>Let say, we build 2 web applications, and since we have only one server to deploy those apps, we will need to run them on different port. Say first app, HelloApp on port 9123 and second app, WelcomeApp on port 9124. It will be quite messy for user to access these app. Don’t we want to offer easy access to our user ? this is how we can use reverse proxy.</p><h3>Reverse Proxy on Go</h3><p>Go has a built-in struct to manage reverse proxy. It is called ReverseProxy on httputil package, and the way to use this also very easy</p><pre>appUrl, _ := url.Parse(target)<br>proxy := httputil.NewSingleHostProxyServer(appUrl)<br>proxy.ServerHTTP(writer, request)</pre><h3>Challenge</h3><p>Like mentioned earlier, reverse proxy by default just re-submit the request from proxy server to application server.</p><p>In above case, say we access <a href="http://myreverseproxy/greet">http://myreverseproxy/greet</a> how do we know which greet method we will access, will it be helloApp/greet or welcomeApp/greet ?</p><p>This is the reason why common reverse proxy need subdomain, because if we have more than one applications to be reversed-proxied we need to have mechanism to recognised which app will be use. Hence, it maybe something like this</p><pre><a href="http://hello.myreverseproxy/greet">http://hello.myproxy.com/greet</a> =&gt; <a href="http://myproxy:9123/greet">http://myproxy.com:9123/greet</a><br>http://welcome.myproxy.com/greet =&gt; http://myproxy.com:9124/greet</pre><p>But, this is not what I want. Because …, on above case, I need to do DNS record to be added, hello.myproxy.com and welcome.myproxy.com. I don’t really want to create so many ticket to be submitted and awake Production Support Team officer to do these stuff</p><p>I want to do reverse proxy on Web Directory instead of subdomain. This is what I want</p><pre><a href="http://hello.myproxy.com/hello/greet">http://myproxy.com/hello/greet</a> =&gt; <a href="http://myproxy.com:9123/greet">http://myproxy.com:9123/greet</a><br>http://myproxy.com/welcome/greet =&gt; http://myproxy.com:9124/greet</pre><p>Kinda cool isn’t ?</p><h3>Let’s do full use case of this Web Directory Reverse Proxy</h3><p>I will start by creating 2 web app, helloApp and welcomeApp</p><p><strong>This is first app, HelloApp</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QLUwki7AfFJ8--ji93D1DQ.png" /><figcaption>helloApp code</figcaption></figure><p>I initiate Server and Mux object separately rather than use default one, because I need to create 3 applications to demonstrate ReverseProxy capabilities and I am too lazy to create 3 different project, hence will combine them all in one project code</p><p><strong>Now lets do, 2nd app, Welcome App</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQU3vSlf4efR2uNJQRH7zg.png" /><figcaption>code for welcomeApp</figcaption></figure><p><strong>And finally proxy app</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jnLSeeAYdbAsAkRx7l87HA.png" /><figcaption>proxyApp code</figcaption></figure><p>So, this proxy app called a magic function reverseProxy, and yes, this function is the key. Here is the code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VnG1FeOmP0LFIyBKFhM00Q.png" /></figure><p><strong>Combine them all in one main</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jcuxbzH-3VR5EIpMQB6Ibw.png" /></figure><p><strong>Showwwwwtime…</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*ZpMx9meOxXeoB1WCb572MQ.png" /><figcaption>Landing of main app is working</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*PydlChFvrMLlIwRoMyj25Q.png" /><figcaption>accessing / of helloApp via reverse proxy</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*jvBxXbd_4_GXlxItvlKwZw.png" /><figcaption>Our header is also generated</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*6NM3vACY6ojqQvSD9aS9lw.png" /><figcaption>Access helloApp /greet, it works</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*XgeZmCkRyxrzxa0qX80pZg.png" /><figcaption>yeayy … welcome also work</figcaption></figure><h3>Where the code is ?</h3><p>All of the code are using standard Go package and can be found on <a href="https://github.com/ariefdarmawan/reverseproxysample">https://github.com/ariefdarmawan/reverseproxysample</a></p><h3>What we can do next with this reverse proxy</h3><p>Well there are tons of possibility to extend usability of reverse proxy</p><ul><li>Enables reverse proxy to multiple server and do process load balance</li><li>Simplifies micro-service process orchestration</li><li>And others</li></ul><p>I hope this post can help us understand what is reverse proxy and how to do reverse proxy <em>(on web directory) </em>using Go. If you have any questions, thoughts or suggestions then I’d love to hear from you!</p><p>Cheers, happy coding</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef7bacb11c8d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kanoteknologi/how-to-do-web-directory-reverse-proxy-on-go-ef7bacb11c8d">How to do web directory reverse proxy on Go ?</a> was originally published in <a href="https://medium.com/kanoteknologi">KANO Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>