<?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: diar</title>
    <description>The latest articles on Forem by diar (@didslm).</description>
    <link>https://forem.com/didslm</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%2F96475%2F40b14de8-f61e-403f-a4ac-26da27abe458.jpg</url>
      <title>Forem: diar</title>
      <link>https://forem.com/didslm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/didslm"/>
    <language>en</language>
    <item>
      <title>Go Interview basic questions</title>
      <dc:creator>diar</dc:creator>
      <pubDate>Tue, 18 Mar 2025 13:08:13 +0000</pubDate>
      <link>https://forem.com/didslm/go-interview-basic-questions-1bpl</link>
      <guid>https://forem.com/didslm/go-interview-basic-questions-1bpl</guid>
      <description>&lt;p&gt;These are some basic GO questions that I've gathered from the interviews.&lt;/p&gt;

&lt;p&gt;I will be posting the questions Post As You Go, where I will gather a post from different interviews that I attend.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;What is a &lt;strong&gt;string&lt;/strong&gt; in go?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Beisdes that it is just a built in type&lt;br&gt;
It's immutable.&lt;br&gt;
It supports UTF-8, which means, it supports all the world languages.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The difference between an &lt;strong&gt;array&lt;/strong&gt; and a &lt;strong&gt;slice&lt;/strong&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Array is fixed size and slices are dynamic which use arrays under the hood, so you can add as many values as you want.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you catch a &lt;strong&gt;panic&lt;/strong&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By using recover.&lt;br&gt;
Although keep in mind that the recover has to be inside of a deferr func.&lt;br&gt;
Since the panic stops the execution, defer is executed if there is a panic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;//... rest of the code&lt;/span&gt;
&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;recover&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Recovered in f"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}()&lt;/span&gt;

&lt;span class="c"&gt;//... rest of the code&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Normally libraries handle panics in their internal code, but they should always return proper error, so you should never get a panic from modules.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;What is the difference between &lt;strong&gt;any&lt;/strong&gt; and &lt;strong&gt;interface{}&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There is no difference.&lt;br&gt;
&lt;code&gt;any&lt;/code&gt; is an alias for &lt;code&gt;interface{}&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;Thanks for your attention.&lt;br&gt;
Is there anything you would add?&lt;/p&gt;

</description>
      <category>go</category>
      <category>programming</category>
    </item>
    <item>
      <title>File Upload Wrapper Library</title>
      <dc:creator>diar</dc:creator>
      <pubDate>Tue, 14 Mar 2023 14:11:16 +0000</pubDate>
      <link>https://forem.com/didslm/file-upload-wrapper-library-33f0</link>
      <guid>https://forem.com/didslm/file-upload-wrapper-library-33f0</guid>
      <description>&lt;p&gt;The File Upload Wrapper is a PHP library that simplifies file uploads by providing a set of easy-to-use classes that handle common validation and processing tasks. &lt;br&gt;
With this library, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Validate uploaded files with ease&lt;/li&gt;
&lt;li&gt;Process uploaded files with targeted validations for specific fields&lt;/li&gt;
&lt;li&gt;Simplify the file upload process with a set of easy-to-use classes&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;To use the library, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the library using Composer:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require didslm/file-upload-wrapper
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Import the classes you need:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Didslm\FileUpload\Uploader&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Didslm\FileUpload\File&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Didslm\FileUpload\Validation\FileSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Didslm\FileUpload\Validation\FileType&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Didslm\FileUpload\Validation\Dimension&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Didslm\FileUpload\FieldValidation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Didslm\FileUpload\Attributes\Image&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Didslm\FileUpload\Attributes\Document&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Didslm\FileUpload\Exceptions\FileUploadException&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Use the upload() method to handle file uploads for your entity:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;#[Image(requestField: "request_field", dir: "/public")]&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$image&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="na"&gt;#[Image(requestField: "profile_field", dir: "/public", required: false)]&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$profile&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nv"&gt;$product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nc"&gt;Uploader&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;upload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileType&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;JPEG&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;MB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Handling File Uploads for an Entity
&lt;/h3&gt;

&lt;p&gt;The following code shows an example of how to use the library to handle file uploads for an entity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//...&lt;/span&gt;
    &lt;span class="na"&gt;#[Image(requestField: "request_field", dir: "/public")]&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$image&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="na"&gt;#[Image(requestField: "profile_field", dir: "/public", required: false)]&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$profile&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getImageFilename&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getProfileFilename&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;Product&lt;/code&gt; class has two properties &lt;code&gt;image&lt;/code&gt; and &lt;code&gt;profile&lt;/code&gt; that are decorated with the &lt;code&gt;Image&lt;/code&gt; attribute. &lt;/p&gt;

&lt;h3&gt;
  
  
  Types
&lt;/h3&gt;

&lt;p&gt;In the following example you will see a list of available Attribute types:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="na"&gt;#[new Image(requestName: 'file_upload_field', dir: '/upload/dir')]&lt;/span&gt;
&lt;span class="na"&gt;#[new Document(requestName: 'cv_file', dir: '/upload/dir')]&lt;/span&gt;
&lt;span class="na"&gt;#[new Video(requestName: 'video_file', dir: '/upload/dir')]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Image&lt;/code&gt; attribute provides metadata to the library to process the files correctly during the upload.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Document&lt;/code&gt; attribute provides metadata to the library to process the files correctly during the upload.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Video&lt;/code&gt; attribute provides metadata to the library to process the files correctly during the upload.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;upload()&lt;/code&gt; method is then called on the &lt;code&gt;Uploader&lt;/code&gt; class with the &lt;code&gt;Product&lt;/code&gt; object and an array of validation rules as its parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nc"&gt;Uploader&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;upload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileType&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;JPEG&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;MB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$product&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getImageFilename&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Handling Exceptions
&lt;/h2&gt;

&lt;p&gt;The library provides a &lt;code&gt;FileUploadException&lt;/code&gt; class that all exceptions thrown by the library extend. This means that you can catch all exceptions using &lt;code&gt;FileUploadException&lt;/code&gt; in a try-catch block, as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Uploader&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;upload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileType&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;PNG&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;MB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;FileUploadException&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// handle exception&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Validation
&lt;/h2&gt;

&lt;p&gt;The library provides several validation classes that you can use to validate uploaded files. These classes can be passed as parameters to the &lt;code&gt;upload()&lt;/code&gt; method to specify the validation rules for the files being uploaded.&lt;/p&gt;

&lt;h3&gt;
  
  
  Type
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;FileType&lt;/code&gt; class is used to check the file type. You can specify the types of files allowed by passing an array of file types to the constructor. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileType&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;PNG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;JPEG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;GIF&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Size
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;FileSize&lt;/code&gt; class is used to validate the file size. You can specify the maximum file size allowed by passing the size in bytes to the constructor. Alternatively, you can use the Size class to specify the size in a more readable format. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;MB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;KB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Dimension
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;Dimension&lt;/code&gt; class is used to validate the dimensions of images. You can specify the maximum width and height of the image by passing them as parameters to the constructor. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dimension&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Targeted Validations
&lt;/h3&gt;

&lt;p&gt;You can also target specific fields in your entity with a set of validations. &lt;br&gt;
To do this, you can use the &lt;code&gt;FieldValidations&lt;/code&gt; class, which takes the request field name as it's first parameter and an array of validation rules as its second parameter. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$profileValidations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FieldValidations&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"profile_field"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dimension&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;MB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="nc"&gt;Uploader&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;upload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileType&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;PNG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;JPEG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;GIF&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
    &lt;span class="nv"&gt;$profileValidations&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, we are specifying a set of validation checks that apply to the profile field in the Product entity. These checks will only be applied to the profile image uploaded by the user.&lt;/p&gt;




&lt;p&gt;Handling file uploads can be a complicated and error-prone task, but with this library, you can simplify the process and focus on building the features that matter. If you have any questions or feedback, feel free to reach out to the author on &lt;a href="https://twitter.com/slmdiar" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; or &lt;a href="https://linkedin.com/in/diarselimi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>php</category>
      <category>beginners</category>
      <category>programming</category>
      <category>wecoded</category>
    </item>
    <item>
      <title>How to start contributing in open-source.</title>
      <dc:creator>diar</dc:creator>
      <pubDate>Thu, 02 Feb 2023 00:00:00 +0000</pubDate>
      <link>https://forem.com/didslm/how-to-start-contributing-in-open-source-3go7</link>
      <guid>https://forem.com/didslm/how-to-start-contributing-in-open-source-3go7</guid>
      <description>&lt;p&gt;This article is meant to tell you how easy it is to start contributing on public repositories and get feedback from people with a lot of experience.&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>php</category>
      <category>career</category>
    </item>
    <item>
      <title>Loading environment values into PHP classes</title>
      <dc:creator>diar</dc:creator>
      <pubDate>Wed, 01 Feb 2023 00:00:00 +0000</pubDate>
      <link>https://forem.com/didslm/loading-environment-values-into-php-classes-40ik</link>
      <guid>https://forem.com/didslm/loading-environment-values-into-php-classes-40ik</guid>
      <description>&lt;p&gt;Load environment variables with this library into php classes, easy to use and test, you can easily contribute to this open source project, code logic is very small and there is no learning curve.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fr3abex47ky3po248an0n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fr3abex47ky3po248an0n.png" alt="Image description" width="800" height="939"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>library</category>
      <category>php</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Is anyone thinking on starting a podcast about development?</title>
      <dc:creator>diar</dc:creator>
      <pubDate>Tue, 31 Jan 2023 14:32:22 +0000</pubDate>
      <link>https://forem.com/didslm/is-anyone-thinking-on-starting-a-podcast-about-development-5hdo</link>
      <guid>https://forem.com/didslm/is-anyone-thinking-on-starting-a-podcast-about-development-5hdo</guid>
      <description>&lt;h3&gt;
  
  
  If you are
&lt;/h3&gt;

&lt;p&gt;Then reach out to me or just post your linkedin profile in the comments, I will reach out and we can discuss.&lt;/p&gt;

&lt;h3&gt;
  
  
  If you are not then you can still reach out on linkedin just in case. :)
&lt;/h3&gt;

</description>
      <category>podcast</category>
      <category>collaboration</category>
      <category>development</category>
    </item>
    <item>
      <title>Loading environment values into go Structs</title>
      <dc:creator>diar</dc:creator>
      <pubDate>Fri, 27 Jan 2023 09:37:36 +0000</pubDate>
      <link>https://forem.com/didslm/loading-environment-values-into-go-structs-2ndl</link>
      <guid>https://forem.com/didslm/loading-environment-values-into-go-structs-2ndl</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;The Env library&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The goal of this library is to be able to load Environment values into GO structs.&lt;/p&gt;

&lt;p&gt;This library is a simple one where it loads four types of values and does not cover arrays or any other logic except what is explained here.&lt;/p&gt;

&lt;p&gt;Supported types are &lt;code&gt;**string,int,int32,int64,float32,float64,bool**&lt;/code&gt; .&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Installation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you have already set up your project in GO and you want to install the library, then all you need to do is &lt;strong&gt;&lt;code&gt;go get github.com/diarselimi/env&lt;/code&gt;&lt;/strong&gt; and that's it.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Basic usage&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After installing this library you can simply use it by importing it and passing the &lt;strong&gt;struct by reference&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The following example will show you, how you can use this with a simple struct which contains tags as a reference to the environment variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"github.com/Diarselimi/env"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;ClientConfig&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;BaseUrl&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="s"&gt;`env:"API_BASE_URL"`&lt;/span&gt;
    &lt;span class="n"&gt;ClientId&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="s"&gt;`env:"API_CLIENT_ID"`&lt;/span&gt;
    &lt;span class="n"&gt;Secret&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="s"&gt;`env:"API_SECRET"`&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;ClientConfig&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PopulateWithEnv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Advanced usage
&lt;/h3&gt;

&lt;p&gt;In this other example you will see how you can use this library by having one central place for all your environment variables, distributed into their own structs.&lt;/p&gt;

&lt;p&gt;The most important part here is the tag type inside structs which is named &lt;code&gt;**obj&lt;/code&gt; .**&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"github.com/Diarselimi/env"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Config&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;SomeApiConfig&lt;/span&gt; &lt;span class="n"&gt;ClientConfig&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
    &lt;span class="n"&gt;MysqlConfig&lt;/span&gt; &lt;span class="n"&gt;SqlConfig&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;ClientConfig&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;BaseUrl&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="s"&gt;`env:"API_BASE_URL"`&lt;/span&gt;
    &lt;span class="n"&gt;ClientId&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="s"&gt;`env:"API_CLIENT_ID"`&lt;/span&gt;
    &lt;span class="n"&gt;Secret&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="s"&gt;`env:"API_SECRET"`&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;SqlConfig&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Host&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="s"&gt;"MYSQL_HOST"&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
    &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="s"&gt;"MYSQL_USER"&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PopulateWithEnv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can see the tag types in the structs which contain &lt;code&gt;**env**&lt;/code&gt; and &lt;code&gt;**obj**&lt;/code&gt; , the library will look and fill them with necessary data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Contribution
&lt;/h3&gt;

&lt;p&gt;The library is very new and does not contain much logic, if you are new into GO and want to contribute to this project feel free to create a pull request and I will review your code.&lt;/p&gt;

&lt;p&gt;Your chance to start contributing when a project is small are way higher because there is no learning curve there are just three methods that do the job.&lt;/p&gt;

&lt;p&gt;You can support by writing test scenarios which also help a lot on making the library more stable on future functionalities.&lt;/p&gt;

&lt;p&gt;If you are not ready to contribute then I would appreciate any other support &lt;a href="https://github.com/diarselimi/env" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt; like give it a star ⭐ if you think it's worth it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The env library will provide you with a simple functionality which can help you load your environment values into go structs.&lt;/p&gt;

&lt;p&gt;If you were thinking to contribute in open source then this is your chance to do so.&lt;/p&gt;

&lt;p&gt;You can use this library for your project or you can contribute by adding support for other types like arrays etc.&lt;/p&gt;

</description>
      <category>library</category>
      <category>go</category>
      <category>opensource</category>
    </item>
    <item>
      <title>As a Developer what should I do next, after ChatGPT release?</title>
      <dc:creator>diar</dc:creator>
      <pubDate>Wed, 07 Dec 2022 11:30:00 +0000</pubDate>
      <link>https://forem.com/didslm/as-a-developer-what-should-i-do-next-after-chatgpt-release-39m5</link>
      <guid>https://forem.com/didslm/as-a-developer-what-should-i-do-next-after-chatgpt-release-39m5</guid>
      <description>&lt;p&gt;As a developer, you may be wondering what to do next now that ChatGPT has been released. ChatGPT is a powerful tool that can help you quickly and easily answer programming questions, but it's important to remember that it's not a replacement for your skills and expertise as a developer.&lt;/p&gt;

&lt;p&gt;So what should you do next? Here are a few suggestions:&lt;/p&gt;

&lt;p&gt;First, continue to develop and improve your skills. ChatGPT is a useful tool, but it's not a substitute for the knowledge and experience that you have as a developer. By staying up to date with the latest technologies and best practices, and by working on challenging projects that push you to grow, you can continue to build your skills and expertise.&lt;/p&gt;

&lt;p&gt;Second, explore new areas of development. ChatGPT can answer many common programming questions, but it can't answer everything. By branching out into new areas of development, such as machine learning or cloud computing, you can expand your knowledge and capabilities, and position yourself for success in the future.&lt;/p&gt;

&lt;p&gt;Third, consider taking on more responsibility. As a developer, you may have the opportunity to lead a team or manage a project. This can be a great way to gain valuable leadership and management experience, and can help you advance your career.&lt;/p&gt;

&lt;p&gt;Finally, don't be afraid to try new things. The world of development is constantly changing, and new technologies and approaches are always emerging. By staying open to new ideas and opportunities, you can continue to grow and thrive as a developer.&lt;/p&gt;

&lt;p&gt;In summary, ChatGPT is a valuable tool, but it's not the end of the road for your career as a developer. By continuing to develop your skills, exploring new areas, taking on new challenges, and staying open to change, you can continue to succeed and thrive in your career.&lt;/p&gt;

&lt;h3&gt;
  
  
  Update
&lt;/h3&gt;

&lt;p&gt;It's true that ChatGPT can quickly and easily generate articles about programming topics. However, this doesn't necessarily mean that you should stop writing articles yourself. There are still many good reasons to write your own articles, even if ChatGPT is capable of doing it as well.&lt;/p&gt;

&lt;p&gt;First, writing your own articles can help you deepen your knowledge and understanding of the topic. By researching and writing about a topic in your own words, you can gain a more thorough understanding of the material than you would by simply using ChatGPT to generate an article.&lt;/p&gt;

&lt;p&gt;Second, writing your own articles can help you develop your own unique perspective and voice. While ChatGPT can generate articles that are technically accurate, they may not always reflect your own thoughts and opinions. By writing your own articles, you can share your own insights and experiences, and contribute to the broader conversation in your field.&lt;/p&gt;

&lt;p&gt;Third, writing your own articles can be a valuable way to build your reputation and credibility as a developer. By sharing your own original content, you can establish yourself as an authority in your field, and demonstrate your expertise and knowledge to others.&lt;/p&gt;

&lt;p&gt;Overall, while ChatGPT can be a useful tool for generating articles about programming, it shouldn't be a replacement for your own writing. Writing your own articles can be a valuable way to deepen your knowledge, develop your perspective, and build your reputation as a developer.&lt;/p&gt;

&lt;p&gt;Let's connect on &lt;a href="https://twitter.com/slmdiar" rel="noopener noreferrer"&gt;twitter&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Layered Architecture Style</title>
      <dc:creator>diar</dc:creator>
      <pubDate>Fri, 02 Dec 2022 08:10:58 +0000</pubDate>
      <link>https://forem.com/didslm/layered-architecture-style-3f03</link>
      <guid>https://forem.com/didslm/layered-architecture-style-3f03</guid>
      <description>&lt;p&gt;Layered architecture, is an architecture pattern that helps for having a more organized and structured codebase.&lt;/p&gt;

&lt;p&gt;Each layer has its distinct job and all the layers communicate via well-defined interfaces.&lt;/p&gt;

&lt;p&gt;This architecture helps us with maintainability and scalability and is often used on enterprise applications.&lt;/p&gt;

&lt;p&gt;You should be strict about not letting these layers have direct dependencies between layers, otherwise, you will lose the benefits of this architectural style.&lt;/p&gt;

&lt;p&gt;Usually, the communication or interaction between layers is top-down at higher levels of the application such as user interaction using lower parts of the application such as the Database.&lt;/p&gt;

&lt;p&gt;The key idea of this architectural style is to have a clear separation of concerns.&lt;/p&gt;

&lt;p&gt;Keep in touch on twitter &lt;a href="https://twitter.com/slmdiar" rel="noopener noreferrer"&gt;@slmdiar&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>design</category>
      <category>pattern</category>
    </item>
    <item>
      <title>Let's Connect on Twitter</title>
      <dc:creator>diar</dc:creator>
      <pubDate>Thu, 01 Dec 2022 20:57:28 +0000</pubDate>
      <link>https://forem.com/didslm/lets-connect-on-twitter-nmi</link>
      <guid>https://forem.com/didslm/lets-connect-on-twitter-nmi</guid>
      <description>&lt;p&gt;I have a new account on twitter and looking for engineers and open minded people to connect with.&lt;br&gt;
Whoever follows I will follow back :).&lt;/p&gt;

&lt;p&gt;Twitter is a great platform to meet new people, share ideas, and stay up-to-date with the latest news. I'm always looking for new connections and conversations, so come join me and let's get connected!&lt;/p&gt;

&lt;p&gt;You can find me on Twitter &lt;a href="https://twitter.com/slmdiar" rel="noopener noreferrer"&gt;@slmdiar&lt;/a&gt;, and I look forward to connecting with you soon.&lt;/p&gt;

</description>
      <category>community</category>
      <category>support</category>
      <category>engagement</category>
    </item>
    <item>
      <title>Go Channels, Waitgroups, and Go Routines</title>
      <dc:creator>diar</dc:creator>
      <pubDate>Tue, 29 Nov 2022 10:52:33 +0000</pubDate>
      <link>https://forem.com/didslm/go-channels-waitgroups-and-go-routines-4dm2</link>
      <guid>https://forem.com/didslm/go-channels-waitgroups-and-go-routines-4dm2</guid>
      <description>&lt;h3&gt;
  
  
  Go Channels, Waitgroups, and Go Routines
&lt;/h3&gt;

&lt;p&gt;Go is a powerful and efficient programming language that has become increasingly popular in recent years. It has become a go-to language for many developers and is used in a variety of applications. One of the features that makes Go so powerful and efficient is its ability to use channels, waitgroups, and go routines. This article will explain what channels, waitgroups, and go routines are and how they work together to help speed up development and improve the efficiency of applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are Go Channels?
&lt;/h3&gt;

&lt;p&gt;Go Channels are data structures that allow a program to send and receive messages between goroutines. These messages can be of any type and are sent over a channel, allowing for communication between goroutines without having to use locks, mutexes, or other synchronization techniques. A channel can be buffered, meaning that messages can be sent even if the receiver is not yet ready to receive them.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are Waitgroups?
&lt;/h3&gt;

&lt;p&gt;Waitgroups are a synchronization primitive that let you wait for a group of goroutines to finish executing. Waitgroups can be used to ensure that all goroutines have finished before continuing execution. This allows for synchronization and coordination between different threads of processing units.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are goroutines?
&lt;/h3&gt;

&lt;p&gt;Goroutines are lightweight threads of execution. They are used to run functions concurrently and can be used to speed up the execution of certain tasks. Goroutines have access to the same memory address space and can share data, allowing multiple goroutines to efficiently work together.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do Channels, Waitgroups, and Goroutines Work Together?
&lt;/h3&gt;

&lt;p&gt;Channels, waitgroups, and goroutines can be used together to create efficient applications that are capable of performing multiple tasks simultaneously. By using channels, waitgroups, and goroutines together, developers can create applications that can perform multiple functions at the same time, allowing them to create more efficient applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Go Channels, waitgroups, and goroutines are powerful tools that can be used to create efficient applications. They allow for communication between goroutines and can be used to synchronize tasks and speed up development. By using these tools together, developers can create powerful applications that can perform multiple tasks simultaneously.&lt;/p&gt;

</description>
      <category>go</category>
      <category>channels</category>
      <category>goroutines</category>
      <category>waitgroup</category>
    </item>
    <item>
      <title>Using Mutex with GO on a real-world project.</title>
      <dc:creator>diar</dc:creator>
      <pubDate>Thu, 17 Nov 2022 21:02:56 +0000</pubDate>
      <link>https://forem.com/didslm/using-mutex-with-go-on-a-real-world-project-25id</link>
      <guid>https://forem.com/didslm/using-mutex-with-go-on-a-real-world-project-25id</guid>
      <description>&lt;h3&gt;
  
  
  What will I learn?
&lt;/h3&gt;

&lt;p&gt;I will be able to understand what is a Mutex,&lt;br&gt;
and how it works in concurrent processes.&lt;br&gt;
I will apply a mutex on a real-world project to see how we can benefit from it.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is a Mutex?
&lt;/h3&gt;

&lt;p&gt;Mutex is a library that works on locking methods to not be accessible from other concurrent processes&lt;br&gt;
until the mutex says that it's open.&lt;br&gt;
Think of a mutex as the traffic police, and when the police block a road that's a &lt;code&gt;Lock()&lt;/code&gt;, no car will pass until the Police open &lt;code&gt;Unlock()&lt;/code&gt; the road.&lt;br&gt;
&lt;a href="https://media2.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%2Fyecqiwsvo6j1shwbkboy.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fyecqiwsvo6j1shwbkboy.jpg" alt="Road block" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  How does it work?
&lt;/h3&gt;

&lt;p&gt;As I would read in the &lt;a href="https://pkg.go.dev/sync#Mutex" rel="noopener noreferrer"&gt;Go docs&lt;/a&gt; a Mutex must not be copied,&lt;br&gt;
if I call the &lt;code&gt;Lock()&lt;/code&gt; method then the mutex is locked and any other lock call will be waiting for it to be &lt;code&gt;Unlock()&lt;/code&gt;-ed.&lt;br&gt;
If I call the &lt;code&gt;Unlock()&lt;/code&gt; method then the mutex will unblock itself and tell the lock method that &lt;code&gt;Mutex&lt;/code&gt; is open.&lt;br&gt;
Every time I copy a mutex then the state is unlocked, meaning it will have no effect.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Before I describe how to apply on a project, try to set up &lt;a href="https://github.com/Diarselimi/giftem#readme" rel="noopener noreferrer"&gt;this project&lt;/a&gt; in your maching, and see how it works.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  How do I apply it on a project?
&lt;/h3&gt;

&lt;p&gt;This is a project that I was working on, it's about assigning gifs to employees, and each employee has to have one gift,&lt;br&gt;
first come first serve.&lt;br&gt;
I have employees and gifts in two json files and they look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;//gifts&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;json&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"netflix card"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"music"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"film"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pets"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"scifi"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"gold plated water bottle"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"categories"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"power lifting"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"triathlons"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"football"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"crossfit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"handball"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"running"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="err"&gt;//employees&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;json&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"severin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"interests"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"high end audio"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"photography"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sitting comfortably"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"oliver"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"interests"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pets"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"scifi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"music making"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The examples are just one object in the array but if you look at the files there are more data.&lt;/p&gt;

&lt;p&gt;Next you will see the project structure &lt;a href="https://github.com/Diarselimi/giftem" rel="noopener noreferrer"&gt;in github&lt;/a&gt;.&lt;br&gt;
The &lt;strong&gt;main.go&lt;/strong&gt; file has the following content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;///...&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;mutex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Mutex&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="c"&gt;//here we initialise Mutex, keep in mind this is outside of the methods.&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;employeeId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;strconv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Atoi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;URL&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Employee with id %s not found"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;URL&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;mediator&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CommandMediator&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Mu&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;mutex&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="c"&gt;//here we pass the mutex by reference&lt;/span&gt;
    &lt;span class="n"&gt;mediator&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewAssignGiftToEmployeeCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;employeeId&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

    &lt;span class="n"&gt;mediator&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HandleFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ListenAndServe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;":8080"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If I go ahead and open &lt;code&gt;CommandMediator&lt;/code&gt; I will see that I use the mutex there to &lt;code&gt;Lock()&lt;/code&gt; and &lt;code&gt;defer Unlock()&lt;/code&gt;,&lt;br&gt;
and &lt;code&gt;defer&lt;/code&gt; is like saying execute this when you are done.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;CommandMediator&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Mu&lt;/span&gt;       &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Mutex&lt;/span&gt; &lt;span class="c"&gt;// important&lt;/span&gt;
    &lt;span class="n"&gt;commands&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="n"&gt;Command&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;///...&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cm&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;CommandMediator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;cm&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Mu&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Lock&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c"&gt;//locking&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;cm&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Mu&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Unlock&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c"&gt;//unlocking when job is done&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;cm&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;commands&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c"&gt;// executing the command&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I can see in the method &lt;code&gt;Run()&lt;/code&gt; above, I am calling the mutex that is being passed from the main file, and then locking it.&lt;br&gt;
So that means that the mutex that I am getting it's the same mutex that everyone else is getting when sending a request.&lt;br&gt;
So that makes sense since we are passing mutex by reference and other people have the same instance of it,&lt;br&gt;
someone might be faster than me in locking it then I must wait for the &lt;code&gt;Unlock()&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  How long do I have to wait for my request?
&lt;/h3&gt;

&lt;p&gt;Turns out it all depends on how your project is organized, in my small project I have blocked the mediator where the commands are executed,&lt;br&gt;
meaning no one can execute the &lt;code&gt;Run()&lt;/code&gt; until the first process is done.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cm&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;CommandMediator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;cm&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Mu&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Lock&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;cm&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Mu&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Unlock&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;cm&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;commands&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make the change more obvious I have added a &lt;code&gt;time.Sleep(5 * time.Second)&lt;/code&gt; which will sleep for 5 seconds,&lt;br&gt;
this is for me to try to simulate two requests at the same time.&lt;br&gt;
So every time I run the command it will be blocked for 5 seconds.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I see the effect?
&lt;/h3&gt;

&lt;p&gt;Since I have the project on my machine, I can open a terminal and run the application by executing &lt;code&gt;go run main.go&lt;/code&gt;,&lt;br&gt;
next step would be to open the following link twice &lt;a href="http://localhost:8080/1" rel="noopener noreferrer"&gt;http://localhost:8080/1&lt;/a&gt;,&lt;br&gt;
one will show you the gift one will show it after 5 seconds.&lt;/p&gt;

&lt;p&gt;As a challenge I could try to disable the mutex in the mediator and see what happens when I click the link above twice or even more.&lt;/p&gt;

</description>
      <category>go</category>
      <category>mutex</category>
      <category>concurrency</category>
    </item>
    <item>
      <title>what is programming? Summary of 10 other articles.</title>
      <dc:creator>diar</dc:creator>
      <pubDate>Sun, 26 Jun 2022 13:20:18 +0000</pubDate>
      <link>https://forem.com/didslm/what-is-programming-summary-of-10-other-aticles-5cl1</link>
      <guid>https://forem.com/didslm/what-is-programming-summary-of-10-other-aticles-5cl1</guid>
      <description>&lt;p&gt;Programming languages are used in computer programming to implement algorithms.&lt;/p&gt;

&lt;p&gt;High-Level Languages are programming languages like Java, Python, C, C , etc which helps programmer to write programs which is independent with the type of computer.&lt;/p&gt;

&lt;p&gt;"Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result." Doing SQL is considered as programming even though for sure there is no executable and its just interpreted by database engine.&lt;/p&gt;

&lt;p&gt;Programming involves activities such as analysis, developing understanding, generating algorithms, verification of requirements of algorithms including their correctness and resources consumption, and implementation of algorithms in a target programming language.&lt;/p&gt;

&lt;p&gt;A computer program is usually written by a computer programmer in a programming language.&lt;/p&gt;

&lt;p&gt;Most of today's high-level languages support object oriented programming or are object oriented programming languages.&lt;/p&gt;

&lt;p&gt;1c. STRUCTURED PROGRAMMING. The structured programming method is a simplified form of imperative programming.&lt;/p&gt;

&lt;p&gt;You can program by writing code in a programming language using a text editor or an integrated development environment.&lt;/p&gt;

&lt;p&gt;In computer science, an interpreter is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program- Wikipedia.&lt;/p&gt;

</description>
      <category>summary</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
