<?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: Ega Prasetya</title>
    <description>The latest articles on Forem by Ega Prasetya (@seventech).</description>
    <link>https://forem.com/seventech</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%2F590059%2Fe941228f-8c53-4e8c-a131-9cf1a7f4007c.jpeg</url>
      <title>Forem: Ega Prasetya</title>
      <link>https://forem.com/seventech</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/seventech"/>
    <language>en</language>
    <item>
      <title>Error, Panic, and Recover in Golang</title>
      <dc:creator>Ega Prasetya</dc:creator>
      <pubDate>Sat, 06 Mar 2021 10:21:43 +0000</pubDate>
      <link>https://forem.com/seventech/error-panic-and-recover-in-golang-486l</link>
      <guid>https://forem.com/seventech/error-panic-and-recover-in-golang-486l</guid>
      <description>&lt;p&gt;Ok so here we'll learn about use of &lt;strong&gt;error&lt;/strong&gt; , besides we'll also learn about the use of &lt;strong&gt;Panic&lt;/strong&gt; to set up &lt;em&gt;Panic Error&lt;/em&gt; and &lt;strong&gt;Recover&lt;/strong&gt; to cover it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Using Error
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;error&lt;/strong&gt; is a type which has one property of &lt;em&gt;error()&lt;/em&gt;_ method. This method returns the details of the message error in the string and includes the type which contained the &lt;em&gt;Nil&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;Below is a simple program sample to detect ingestion from the user, whether numeric or not.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frw3dwqrtnwdqi4q979x6.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frw3dwqrtnwdqi4q979x6.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Result, if we type number and string: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Focmr854ipg346angyl4f.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Focmr854ipg346angyl4f.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1iy9mts03apngyjov6l.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1iy9mts03apngyjov6l.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The statement &lt;em&gt;fmt.Scanln(&amp;amp;input)&lt;/em&gt; used to capture typed by the user before he hits the enter, then keeps it as a &lt;em&gt;string&lt;/em&gt; to the &lt;em&gt;input&lt;/em&gt; variable. &lt;/p&gt;

&lt;p&gt;Next, those variables are converted to numerical types using &lt;em&gt;strconv.Atoi()&lt;/em&gt;. The function returns the 2 data, contained by number and err.&lt;/p&gt;

&lt;h1&gt;
  
  
  Panic
&lt;/h1&gt;

&lt;p&gt;Panic is used to display &lt;em&gt;stack trace error&lt;/em&gt; while also halting flow goroutine ( because main() is goroutine, the same drag is also applied ).&lt;/p&gt;

&lt;p&gt;Panic displayed an error message in the console, just like &lt;em&gt;fmt.Println()&lt;/em&gt;. The information of error displayed is stack trace error, so it`s very detailed on hilarious.&lt;/p&gt;

&lt;p&gt;Next, back to your code and changed in block condition else.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsj733urjg3pfweai8x8n.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsj733urjg3pfweai8x8n.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Result: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1se39qmutupesbkq9xty.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1se39qmutupesbkq9xty.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Recover
&lt;/h1&gt;

&lt;p&gt;Recover useful to handle panic error, at the time of panic error &lt;strong&gt;Recover&lt;/strong&gt; take over goroutine are panic (the panic message won`t appear).&lt;/p&gt;

&lt;p&gt;Next, We add the catch() function, this function is a statement that he will revisit the panic error message that was supposed to appear.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2gbvnq9sfog4quoyxmtn.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2gbvnq9sfog4quoyxmtn.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Result: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnw1li17r8989r9rlh92n.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnw1li17r8989r9rlh92n.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk0imltye00b28uopi4k2.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk0imltye00b28uopi4k2.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yeah, we done.&lt;/p&gt;

&lt;p&gt;Follow me on: &lt;br&gt;
&lt;a href="https://github.com/egaprsty" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://instagram.com/svnberr" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>backend</category>
    </item>
    <item>
      <title>Golang Unit Testing </title>
      <dc:creator>Ega Prasetya</dc:creator>
      <pubDate>Fri, 05 Mar 2021 10:14:51 +0000</pubDate>
      <link>https://forem.com/seventech/go-lang-unit-testing-815</link>
      <guid>https://forem.com/seventech/go-lang-unit-testing-815</guid>
      <description>&lt;p&gt;Okay so in the first write i gonna to show you how to implementation Unit Testing in Go, absolutely this is very ez to learn. So lets do it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Create Package
&lt;/h1&gt;

&lt;p&gt;so i created package name is &lt;strong&gt;helper&lt;/strong&gt;, but if you wanna to create another package name it`s not a problem.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5n72jclstpcjo3csiolv.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5n72jclstpcjo3csiolv.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Like the examples above, i made function simple named &lt;strong&gt;Hello World&lt;/strong&gt;. if we`re trying to test it, then it should be done with &lt;strong&gt;Test.go&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Next, Go has a method &lt;em&gt;(t *testing.T)&lt;/em&gt; and then follow the code below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp2mfohmsrgqyg1emsz01.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp2mfohmsrgqyg1emsz01.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd301ehexxqyml30veqze.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd301ehexxqyml30veqze.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;if we wanna to run this code, we got to the helper folder first.&lt;/p&gt;

&lt;p&gt;In above, we create a logic which only contains an error by using the &lt;em&gt;panic&lt;/em&gt; function.&lt;/p&gt;

&lt;p&gt;In Go, we can perform an error other than panic, we can use &lt;strong&gt;t.Fail()&lt;/strong&gt; and &lt;strong&gt;t.FailNow()&lt;/strong&gt; .&lt;/p&gt;

&lt;p&gt;It`s the difference when using t.Fail() and t.FailNow()&lt;/p&gt;

&lt;p&gt;First, we change in Hello_World.go &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8fe2tdkhvjcmm8th5by.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8fe2tdkhvjcmm8th5by.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we create other function in Hello_World_test.go&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhc24n934ckp32crxklkt.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhc24n934ckp32crxklkt.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Result :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filodhzxjd6405yq6jgoz.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filodhzxjd6405yq6jgoz.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we got this, thx for read and sorry for the mistakes, Enjoy.&lt;/p&gt;

</description>
      <category>go</category>
      <category>webdev</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
