<?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>DEV Community: Gabe</title>
    <description>The latest articles on DEV Community by Gabe (@gabeisthinking).</description>
    <link>https://dev.to/gabeisthinking</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%2F366611%2Facc7e72c-1fed-4090-9eaf-5748a9531c27.jpeg</url>
      <title>DEV Community: Gabe</title>
      <link>https://dev.to/gabeisthinking</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gabeisthinking"/>
    <language>en</language>
    <item>
      <title>Golang Fasthttp Middleware</title>
      <dc:creator>Gabe</dc:creator>
      <pubDate>Tue, 14 Jun 2022 21:43:51 +0000</pubDate>
      <link>https://dev.to/gabeisthinking/golang-fasthttp-middleware-10n1</link>
      <guid>https://dev.to/gabeisthinking/golang-fasthttp-middleware-10n1</guid>
      <description>&lt;p&gt;I am using &lt;a href="https://github.com/valyala/fasthttp"&gt;FastHttp&lt;/a&gt; to implemente Http in go. Most people are using Gorilla Mux, but I decided to try a different http implementation.&lt;/p&gt;

&lt;p&gt;There are scenarios where a request should chained, I mean, we must execute previous actions before handling the request resolver itself. The most common case is evaluating Authorization before executing the business.&lt;/p&gt;

&lt;p&gt;Having said that, lets imagine a scenario where we must have an endpoint that must be protected by an Auth middleware, check for token and if its valid you can execute the business   otherwise you get a 401 http status.&lt;/p&gt;

&lt;p&gt;First set up the router&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;router := fasthttprouter.New()
router.GET("/", GetProducts)
fasthttp.ListenAndServe(":5002", router.Handler)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The GetProducts is a function that simply respond with a product object. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func GetProducts(ctx *fasthttp.RequestCtx) {

    product := &amp;amp;productModel.Product{}
    product.Id = "123890"
    product.Name = "Shoes"
    product.Price = 100.30

    json.NewEncoder(ctx).Encode(response)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are going to create our Auth Middleware&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func Auth(requestHandler fasthttp.RequestHandler) fasthttp.RequestHandler {
    return func(ctx *fasthttp.RequestCtx) {
        token := string(ctx.Request.Header.Peek("Authorization"))

        if token == "" {
            return 
        } else {
               requestHandler(ctx)
                }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now... we are going to wrap the GetProducts on router.Get method wit&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;router.GET("/", Auth(GetProducts))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, if you get until here you may want to understand how it works.&lt;/p&gt;

&lt;p&gt;-- add&lt;/p&gt;

</description>
      <category>go</category>
      <category>middlewarer</category>
      <category>fasthttp</category>
      <category>http</category>
    </item>
    <item>
      <title>Checksum</title>
      <dc:creator>Gabe</dc:creator>
      <pubDate>Fri, 29 Apr 2022 23:22:38 +0000</pubDate>
      <link>https://dev.to/gabeisthinking/checksum-3c0g</link>
      <guid>https://dev.to/gabeisthinking/checksum-3c0g</guid>
      <description>&lt;p&gt;When data are transmitted over the internet data could be loss due to signal noise or synchronization error. &lt;strong&gt;Checksum&lt;/strong&gt; is a way to guarantee we have transmitted or received the full data.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Checksum
&lt;/h2&gt;

&lt;p&gt;Checksum is a value that represents the sum of all bits a file have and then turned into a fixed length string. It also related as file's Hash. It can be identified as a very long string composed by letters and numbers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Checksum is important
&lt;/h2&gt;

&lt;p&gt;Its a way to guarantee that the file you wanted is not corrupted or broken. Its a way to ensure all the bites were transferred correct, guaranteeing file's integrity.&lt;/p&gt;

&lt;p&gt;When downloading a file you will receive the file's checksum, when the download is completed, you can validate the checksum you received at the beginning of the download and calculate the current file checksum. If the result is slightly different, you can delete the file and try again or even contact the providers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Incompatible checksum causes
&lt;/h2&gt;

&lt;p&gt;It could be caused by a simple internet error - due a slow or not stable connection or a third party trying to intercept and change your data' transfer&lt;/p&gt;

&lt;h2&gt;
  
  
  Where is it used
&lt;/h2&gt;

&lt;p&gt;You can check on Microsoft's windows checksum by &lt;a href="https://support.microsoft.com/en-gb/topic/d92a713f-d793-7bd8-b0a4-4db811e29559"&gt;running some terminal commands&lt;/a&gt; for example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cooking a Checksum.
&lt;/h2&gt;

&lt;p&gt;Checksum is generated by an algorithm that have an input file and will spit out a Hash - string composed by letters and numbers.&lt;/p&gt;

&lt;p&gt;This algorithm in general terms will count all the bites and then use some techniques involving MD5, SHA-1 or SHA-256 to generate an HASH. The file's size has no influence on HASH length, it could be a 100KB or 100GB it will output an HASH will keep with the same HASH length.&lt;/p&gt;

&lt;p&gt;There is some interesting ways to compute and techniques that could be used, which would make this merely article very long, so, not going to cover it now.&lt;/p&gt;

&lt;p&gt;Its being noticed that MD5 and SHA-1 have generated same HASHes for files with different content, so it would invalidate the file's checksum. Although SHA-256 has no issue related reported.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Checksum is a HASH that is used to check file's integrity after a download. Its generated by algorithms and basically uses MD5 or SHA-1 or SHA-256 as its base and Big Tech firms use it to guarantee you downloaded everything correctly.&lt;/p&gt;

</description>
      <category>checksum</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Hello World!</title>
      <dc:creator>Gabe</dc:creator>
      <pubDate>Thu, 21 Apr 2022 14:38:29 +0000</pubDate>
      <link>https://dev.to/gabeisthinking/hello-world-2cef</link>
      <guid>https://dev.to/gabeisthinking/hello-world-2cef</guid>
      <description>&lt;p&gt;Well, its the most common sentence we write when learning something new or trying a new language. So, its my first blogpost on dev.to and I could not figure out a better approach. &lt;/p&gt;

&lt;p&gt;I am taking a time to learn Go programming language and for this long period I've had a lot of new point of views on how I could develop an application. As I am amused with this new stuffs I thought that I could practice coding and sharing, even that I have not that so clear idea on how things works under the hood, so this way I may keep motivated to write small and focused posts. &lt;/p&gt;

&lt;p&gt;So, which me lucky and hope you can read something form me really soon.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>go</category>
    </item>
  </channel>
</rss>
