<?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 Luthfiarsyad on Medium]]></title>
        <description><![CDATA[Stories by Luthfiarsyad on Medium]]></description>
        <link>https://medium.com/@luthfiarsyad68?source=rss-60daae6a67b8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aheaMjFd-1DowP55VuHT9A.jpeg</url>
            <title>Stories by Luthfiarsyad on Medium</title>
            <link>https://medium.com/@luthfiarsyad68?source=rss-60daae6a67b8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 04:28:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@luthfiarsyad68/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[Securing Go Applications: My Journey into Rate Limiting with GoFiber]]></title>
            <link>https://medium.com/@luthfiarsyad68/securing-go-applications-my-journey-into-rate-limiting-with-gofiber-329fbd18f825?source=rss-60daae6a67b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/329fbd18f825</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[golang-development]]></category>
            <dc:creator><![CDATA[Luthfiarsyad]]></dc:creator>
            <pubDate>Wed, 21 Aug 2024 09:07:58 GMT</pubDate>
            <atom:updated>2024-08-21T09:09:43.445Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*pd_FEbfmH7XsCbcHI8u_nw.jpeg" /><figcaption>Illustration of rate limiter.</figcaption></figure><p>As a passionate Go developer, I often find myself deep in the trenches of building high-performance applications. The elegance and efficiency of Go never cease to amaze me. However, amidst my enthusiasm for coding, I sometimes overlook critical security aspects. One such aspect is protecting applications from Denial-of-Service (DoS) attacks. It was during one of these moments of oversight that I decided to dive deep into Rate Limiting.</p><p><strong>Why Rate Limiting Matters</strong></p><p>In the world of web applications, Rate Limiting is a crucial defense mechanism against DoS attacks. By controlling the number of requests a user can make in a given timeframe, Rate Limiting helps ensure that your server remains responsive and available, even under stress.</p><p><strong>My Exploration of Rate Limiting</strong></p><p>I embarked on this journey to understand how Rate Limiting works and how to implement it in Go. While researching, I discovered that both Gin and GoFiber — two popular Go web frameworks — offer support for Rate Limiting. However, I found that implementing Rate Limiting is more straightforward in GoFiber compared to Gin.</p><p><strong>Rate Limiting in GoFiber: A Simple Approach</strong></p><p>GoFiber’s design philosophy prioritizes simplicity and performance, which extends to its support for Rate Limiting. With GoFiber, you can quickly set up a Rate Limiter to protect your endpoints with minimal configuration. Here’s a brief overview of how I implemented Rate Limiting in a GoFiber application:</p><ol><li><strong>Installation</strong>: Start by installing the necessary GoFiber middleware package for Rate Limiting.</li></ol><pre>go get github.com/gofiber/limiter</pre><p><strong>2. Configuration</strong>: Next, configure the Rate Limiter middleware in your GoFiber application. You can set limits based on IP addresses, request paths, or other criteria.</p><pre>package main<br><br>import (<br>    &quot;github.com/gofiber/fiber/v2&quot;<br>    &quot;github.com/gofiber/limiter/v2&quot;<br>)<br><br>func main() {<br>    app := fiber.New()<br><br>    // Initialize Rate Limiter middleware<br>    app.Use(limiter.New(limiter.Config{<br>        Max:        100, // Maximum number of requests<br>        Expiry:     60 * time.Second, // Time window for rate limiting<br>    }))<br><br>    app.Get(&quot;/&quot;, func(c *fiber.Ctx) error {<br>        return c.SendString(&quot;Hello, World!&quot;)<br>    })<br><br>    app.Listen(&quot;:3000&quot;)<br>}</pre><p><strong>3. Testing</strong>: Finally, test the Rate Limiter to ensure it’s functioning as expected. Send multiple requests to your endpoint and verify that the limiter correctly restricts excessive requests.</p><p>I uses K6 for testing, this below is my testing script for this rate limit test (This step need installation of k6 for prerequisite, and the code uses JS)</p><pre>import http from &#39;k6/http&#39;;<br>import { check, sleep } from &#39;k6&#39;;<br><br>// Configuration for the test<br>export let options = {<br>    vus: 10, // Number of Virtual Users<br>    duration: &#39;1m&#39;, // Duration of the test<br>};<br><br>export default function () {<br>    // Replace with the URL of your GoFiber application<br>    let res = http.get(&#39;http://localhost:3000/&#39;);<br><br>    // Check if the response status is 200 OK<br>    check(res, {<br>        &#39;is status 200&#39;: (r) =&gt; r.status === 200,<br>        &#39;is rate limited&#39;: (r) =&gt; r.headers[&#39;X-RateLimit-Limit&#39;] !== undefined,<br>    });<br><br>    sleep(1); // Sleep for 1 second between requests<br>}</pre><p>Run the code using this command below on your terminal:</p><pre>k6 run rate_limit_test.js</pre><p>This will run if you already installed K6, if you haven’t you can use this <a href="https://k6.io/docs/get-started/installation/">installation link</a>.</p><p><strong>Lessons Learned</strong></p><p>Implementing Rate Limiting in GoFiber was a rewarding experience. It reinforced the importance of considering security measures in application development and demonstrated how GoFiber’s straightforward approach can simplify complex tasks.</p><p>Rate Limiting might seem like a small detail in the grand scheme of application security, but its impact on protecting your server cannot be overstated. I hope this documentation helps other Go developers who are as passionate about secure coding as I am.</p><p><strong>Conclusion</strong></p><p>As I continue to explore the vast landscape of Go development, I’m reminded of the importance of security in every aspect of application design. Rate Limiting is just one piece of the puzzle, but it’s a crucial one. By sharing my experience, I aim to contribute to a community that values both performance and security. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=329fbd18f825" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Week 4 Bootcamp at PT. Phincon Part 3]]></title>
            <link>https://medium.com/@luthfiarsyad68/week-4-bootcamp-at-pt-phincon-part-3-3a7b376bb2bc?source=rss-60daae6a67b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a7b376bb2bc</guid>
            <category><![CDATA[go-tutorial]]></category>
            <dc:creator><![CDATA[Luthfiarsyad]]></dc:creator>
            <pubDate>Mon, 07 Nov 2022 01:50:27 GMT</pubDate>
            <atom:updated>2022-11-07T01:50:27.655Z</atom:updated>
            <content:encoded><![CDATA[<p>We are continuing to learn Go by learning how to use type assertions.</p><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>func Random() interface{} {</pre><pre>return &quot;OK&quot;</pre><pre>}</pre><pre>func main() {</pre><pre>res := Random()</pre><pre>fmt.Println(res)<br></pre><pre>resString := res.(string)</pre><pre>fmt.Println(resString)<br></pre><pre>resInt := res.(int)</pre><pre>fmt.Println(resInt)</pre><pre>}</pre><p>On this point we are validating the type of resStringis by using .(dataType) To validate this, also we can use reflect. Thats why we learn about reflect.</p><h3>Accessing Values in the Form of interface{}</h3><p>If the value is only required to be displayed to the output, you can use .Interface(). Through this method, all types of values can be accessed easily.</p><pre>var number = 23<br>var reflectValue = reflect.ValueOf(number)<br><br>fmt.Println(&quot;tipe  variabel :&quot;, reflectValue.Type())<br>fmt.Println(&quot;nilai variabel :&quot;, reflectValue.Interface())</pre><p>The Interface() function returns an empty interface value or interface{}. The original value itself can be accessed by casting the empty interface.</p><pre>var nilai = reflectValue.Interface().(int)</pre><h3>Accessing Struct Variable Property Information</h3><p>Reflect can be used to retrieve information on all the variable properties of the struct template object, provided that these properties have the public modifier. Immediately we practice, prepare a struct named student.</p><pre>type student struct {<br>    Name  string<br>    Grade int<br>}</pre><p>Create a new method for the struct, with the name method getPropertyInfo(). This method contains code to retrieve and display information for each property belonging to the student struct.</p><pre>func (s *student) getPropertyInfo() {<br>    var reflectValue = reflect.ValueOf(s)<br><br>    if reflectValue.Kind() == reflect.Ptr {<br>        reflectValue = reflectValue.Elem()<br>    }<br><br>    var reflectType = reflectValue.Type()<br><br>    for i := 0; i &lt; reflectValue.NumField(); i++ {<br>        fmt.Println(&quot;nama      :&quot;, reflectType.Field(i).Name)<br>        fmt.Println(&quot;tipe data :&quot;, reflectType.Field(i).Type)<br>        fmt.Println(&quot;nilai     :&quot;, reflectValue.Field(i).Interface())<br>        fmt.Println(&quot;&quot;)<br>    }<br>}</pre><p><strong>Finally, test the method in the main function.</strong></p><pre>func main() {<br>    var s1 = &amp;student{Name: &quot;wick&quot;, Grade: 2}<br>    s1.getPropertyInfo()<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a7b376bb2bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Week 4 Bootcamp at PT. Phincon Part 2]]></title>
            <link>https://medium.com/@luthfiarsyad68/week-4-bootcamp-at-pt-phincon-part-2-c44e4cac4c2b?source=rss-60daae6a67b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/c44e4cac4c2b</guid>
            <category><![CDATA[go-tutorial]]></category>
            <dc:creator><![CDATA[Luthfiarsyad]]></dc:creator>
            <pubDate>Mon, 07 Nov 2022 01:50:21 GMT</pubDate>
            <atom:updated>2022-11-07T01:50:21.919Z</atom:updated>
            <content:encoded><![CDATA[<p>We are learning about interfaces in Go. An interface is a collection of method definitions that have no content (only definitions), which are wrapped with a specific name.</p><p>Interface is a data type. The value of an object of type interface zero value is nil. An interface can start to be used if it already has its contents, namely a concrete object that has at least the same method definition as the one in the interface.</p><h3>What do we need to do to implement an interface?</h3><p>The first thing you need to do to implement an interface is to prepare the interface and its method definitions. The keywords type and interface are used to define the interface.</p><pre>package main<br><br>import &quot;fmt&quot;<br>import &quot;math&quot;<br><br>type hitung interface {<br>    luas() float64<br>    keliling() float64<br>}</pre><p>In the code above, the arithmetic interface has 2 method definitions, area() and perimeter(). This interface will later be used as a data type on the variable, where the variable will accommodate the flat object as a result of the struct that we will create.</p><p>By utilizing the calculation interface, the calculation of the area and circumference of a flat shape can be done, without the need to know what type of flat shape it is.</p><p>Prepare a circular flat-shaped struct, this struct has methods some of which are defined in the compute interface.</p><pre>type lingkaran struct {<br>    diameter float64<br>}<br><br>func (l lingkaran) jariJari() float64 {<br>    return l.diameter / 2<br>}<br><br>func (l lingkaran) luas() float64 {<br>    return math.Pi * math.Pow(l.jariJari(), 2)<br>}<br><br>func (l lingkaran) keliling() float64 {<br>    return math.Pi * l.diameter<br>}</pre><p>The circular structure above has three methods, radius(), area(), and circumference().</p><p>Next, prepare a rectangular flat-built struct.</p><pre>type persegi struct {<br>    sisi float64<br>}<br><br>func (p persegi) luas() float64 {<br>    return math.Pow(p.sisi, 2)<br>}<br><br>func (p persegi) keliling() float64 {<br>    return p.sisi * 4<br>}</pre><p>The difference between a square struct and a circle structure lies in the finger() method. Square structures don’t have that method. But even so, the object variables that were printed on these 2 structs will still be accommodated by the calculated interface template variable, because the two methods defined in the interface also exist in square and circular structs, namely area() and circumference().</p><p>Create a calculation implementation in main.</p><pre>func main() {<br>    var bangunDatar hitung<br><br>    bangunDatar = persegi{10.0}<br>    fmt.Println(&quot;===== persegi&quot;)<br>    fmt.Println(&quot;luas      :&quot;, bangunDatar.luas())<br>    fmt.Println(&quot;keliling  :&quot;, bangunDatar.keliling())<br><br>    bangunDatar = lingkaran{14.0}<br>    fmt.Println(&quot;===== lingkaran&quot;)<br>    fmt.Println(&quot;luas      :&quot;, bangunDatar.luas())<br>    fmt.Println(&quot;keliling  :&quot;, bangunDatar.keliling())<br>    fmt.Println(&quot;jari-jari :&quot;, bangunDatar.(lingkaran).jariJari())<br>}</pre><p>Look at the code above. The variable wakeFlat object is of type computed interface. These variables are used to hold concrete objects made by circular and square structs.</p><p>From these variables, the area() and perimeter() methods are accessed. Golang will automatically direct method calls on the interface to the original method belonging to the struct in question.</p><p>The finger() method on the circular struct will not be accessible because it is not defined in the compute interface. Accessing it forcefully will cause an error.</p><p>To access an undefined method in the interface, the variable must first be cast to the original type of the concrete variable (in this case the type is circle), after which the method will be accessible.</p><p>The method of casting interface objects is a bit unique, namely by writing the name of the destination type in brackets, placed after the interface name using dot notation (like how to access properties, only there are brackets). An example can be seen in the following code. The statement wakeFlat.(circle) is an example of casting on an interface object.</p><pre>var bangunDatar hitung = lingkaran{14.0}<br>var bangunLingkaran lingkaran = bangunDatar.(lingkaran)<br><br>bangunLingkaran.jariJari()</pre><p>Also note, if there is an interface that holds a concrete object where the struct doesn’t have any of the methods defined in the interface, an error will also appear. The point goes back to the original rule, interface variables can only hold objects that at least have all methods defined in their interfaces.</p><h3>Embedded Interface</h3><p>Interfaces can be embedded into other interfaces, just like structs. The method of implementation is also the same, simply by writing the name of the interface you want to embed into the destination interface.</p><p>In the following example, the interfaces named hitung2d and hitung3d are prepared. Both interfaces are then embedded into a new interface called count.</p><pre>package main<br><br>import &quot;fmt&quot;<br>import &quot;math&quot;<br><br>type hitung2d interface {<br>    luas() float64<br>    keliling() float64<br>}<br><br>type hitung3d interface {<br>    volume() float64<br>}<br><br>type hitung interface {<br>    hitung2d<br>    hitung3d<br>}</pre><p>The hitung2d interface contains methods for calculating area and perimeter, while hitung3d contains methods for finding the volume of a plane. Both interfaces are derived from the calculation interface, giving them the ability to calculate area, perimeter, and volume.</p><p>Next, prepare a new struct named cube which has luas(), keliling(), and volume() methods.</p><pre>type kubus struct {<br>    sisi float64<br>}<br><br>func (k *kubus) volume() float64 {<br>    return math.Pow(k.sisi, 3)<br>}<br><br>func (k *kubus) luas() float64 {<br>    return math.Pow(k.sisi, 2) * 6<br>}<br><br>func (k *kubus) keliling() float64 {<br>    return k.sisi * 12<br>}</pre><p>The printed object of the cube struct above will later be accommodated by the count interface print object whose contents are a combination of the hitung2d and hitung3d interfaces.</p><p>Finally, make the implementation in main.</p><pre>func main() {<br>    var bangunRuang hitung = &amp;kubus{4}<br><br>    fmt.Println(&quot;===== kubus&quot;)<br>    fmt.Println(&quot;luas      :&quot;, bangunRuang.luas())<br>    fmt.Println(&quot;keliling  :&quot;, bangunRuang.keliling())<br>    fmt.Println(&quot;volume    :&quot;, bangunRuang.volume())<br>}</pre><p>It can be seen in the code above, through the calculation interface, the area, perimeter, and volume methods can be accessed.</p><p>The pointer is explained that the method pointer can be accessed via ordinary object variables and pointer object variables. An object variable that is printed using a struct that has a method pointer, if it is stored in an interface variable, it must be referenced first. An example can be seen in the code above var bangunRuang hitung = &amp;kubus{4}.</p><h3>Empty Interface</h3><p>Empty interface, denoted by interface{}, is a very special data type. Variables of this type can hold any kind of data, even arrays, pointers, whatever. Data types with this concept are commonly called dynamic typing.</p><p>interface{} is a data type, so the way it is used is the same as in other data types, except that the value entered can be anything. Example:</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br>    var secret interface{}<br><br>    secret = &quot;ethan hunt&quot;<br>    fmt.Println(secret)<br><br>    secret = []string{&quot;apple&quot;, &quot;manggo&quot;, &quot;banana&quot;}<br>    fmt.Println(secret)<br><br>    secret = 12.4<br>    fmt.Println(secret)<br>}</pre><p>interfacekeyword as we know, it is used to create interfaces. But when you add curly braces ({}) behind it (become interface{}), then its use will change, namely as a data type.</p><p>In order not to be confused, consider the following code.</p><pre>var data map[string]interface{}<br><br>data = map[string]interface{}{<br>    &quot;name&quot;:      &quot;ethan hunt&quot;,<br>    &quot;grade&quot;:     2,<br>    &quot;breakfast&quot;: []string{&quot;apple&quot;, &quot;manggo&quot;, &quot;banana&quot;},<br>}</pre><p>In the code above, a data variable of type map[string]interface{} is prepared, which is a collection with a key of type string and a value of type empty interface interface{}.</p><p>Then the variable is initialized, adding curly braces after the declaration keyword for data entry requirements, map[string]interface{}{ /* data */ }.</p><p>From there it can be seen that interface{} is not an object, but a data type.</p><p>Empty Interface itself has an alias for calling purposes, we can use any like it shown in example:</p><pre>var data map[string]any<br><br>data = map[string]any{<br>    &quot;name&quot;:      &quot;ethan hunt&quot;,<br>    &quot;grade&quot;:     2,<br>    &quot;breakfast&quot;: []string{&quot;apple&quot;, &quot;manggo&quot;, &quot;banana&quot;},<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c44e4cac4c2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Week 4 Bootcamp at PT. Phincon]]></title>
            <link>https://medium.com/@luthfiarsyad68/week-4-bootcamp-at-pt-phincon-e447b55dfe0b?source=rss-60daae6a67b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e447b55dfe0b</guid>
            <category><![CDATA[go-tutorial]]></category>
            <dc:creator><![CDATA[Luthfiarsyad]]></dc:creator>
            <pubDate>Mon, 07 Nov 2022 01:50:16 GMT</pubDate>
            <atom:updated>2022-11-07T01:50:16.375Z</atom:updated>
            <content:encoded><![CDATA[<p>In these week we start by learning Struct. Go doesn’t have the classes that exist in other strict OOP languages. But Go has a structure data type called Struct.</p><p>A structure is a collection of variable (or property) and or function (or method) definitions, which are wrapped as a new data type with a specific name. Properties in the struct, the data type can vary. Similar to a map, only the key is predefined, and the data type of each item can be different.</p><p>From a struct, we can create a new variable, which has attributes according to the schema of the struct. We agreed in this book, the variable is called by the term object or object struct.</p><p>The concept of a struct in golang is similar to the concept of a class in OOP, although it is actually different. Here the author uses the concept of OOP as an analogy, with the aim of making it easier to digest the contents of this chapter.</p><p>By utilizing structs, grouping data will be easier, besides that it is neat and easy to maintain.</p><h3>Struct Declaration</h3><p>The keyword type is used for struct declarations. Below is an example of how to use it.</p><p>The student structure is declared to have 2 properties, namely name and grade. Objects created with this struct later have the same schema or structure.</p><h3>Struct Implementation</h3><p>We will use the student structure that has been prepared above to create object variables. The variable property is filled in and then displayed.</p><p>How to create object variables is the same as creating ordinary variables. Just write the variable name followed by the struct name, for example: var s1 student.</p><p>All object variable properties initially have zero values according to their data type.</p><p>Object variable properties can be accessed by using dot notation, for example s1.name. The property value can also be changed, for example s1.grade = 2.</p><h3>Object Struct Initialization</h3><p>The way to initialize object variables is to add curly braces after the struct name. The value of each property can be filled at the time of initialization.</p><p>In the following example, there are 3 object variables declared in different ways.</p><pre>var s1 = student{}<br>s1.name = &quot;wick&quot;<br>s1.grade = 2<br><br>var s2 = student{&quot;ethan&quot;, 2}<br><br>var s3 = student{name: &quot;jason&quot;}<br><br>fmt.Println(&quot;student 1 :&quot;, s1.name)<br>fmt.Println(&quot;student 2 :&quot;, s2.name)<br>fmt.Println(&quot;student 3 :&quot;, s3.name)</pre><p>In the code above, the variable s1 holds the student print object. The variable is then set to its property value.</p><p>The object variable s2 is declared with the same method as s1, the difference is that in s2 the value of its property is filled directly when declared. The first value will be the value of the first property (namely name), and then in order.</p><p>In the s3 declaration, the property is also filled in when printing the object. It’s just that, what is filled in is only the name. This method is quite effective if used to create new objects whose property values do not all have to be prepared at the beginning. Another advantage of using this method is that the determination of property values can be done in a non-sequential manner. For example:</p><pre>var s4 = student{name: &quot;Wira&quot;, grade: 2}<br>var s5 = student{grade: 2, name: &quot;Nagara&quot;}</pre><h3>Embedded Struct</h3><p>Embedded struct is a mechanism for embedding a struct as a property of another struct. To make it easier to understand, let’s discuss the following code.</p><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>type student struct {</pre><pre>grade int</pre><pre>person</pre><pre>}</pre><pre>type person struct {</pre><pre>name string</pre><pre>age  int</pre><pre>}</pre><pre>func main() {</pre><pre>var s1 = student{}</pre><pre>s1.name = &quot;Wick&quot;</pre><pre>s1.age = 21</pre><pre>s1.grade = 2</pre><pre>fmt.Println(&quot;name : &quot;, s1.name)</pre><pre>fmt.Println(&quot;age : &quot;, s1.age)</pre><pre>fmt.Println(&quot;age : &quot;, s1.person.age)</pre><pre>fmt.Println(&quot;grade : &quot;, s1.grade)</pre><pre>}</pre><p>In the code above, a person struct is prepared with the available properties are name and age. A student struct is also prepared with a grade property. The person struct is embedded into the student struct. The method is quite easy, namely by writing the name of the struct you want to embed into the body of the target struct.</p><p>Embedded struct is mutable, its property value can be changed.</p><p>Especially for properties that are not real properties (properties derived from other structs), they can be accessed by first accessing the parent struct, for example s1.person.age. The returned value has the same reference as s1.age.</p><h3>Anonymous Struct</h3><p>Anonymous structs are structs that are not declared at the beginning as a new data type, but are directly declared when the object is created. This technique is quite efficient for creating object variables whose structs are only used once.</p><pre>// anonymous struct without filling property<br>var s1 = struct {<br>    person<br>    grade int<br>}{}<br><br>// anonymous struct with property filling<br>var s2 = struct {<br>    person<br>    grade int<br>}{<br>    person: person{&quot;wick&quot;, 21},<br>    grade:  2,<br>}</pre><h3><strong>Combination of Slice &amp; Struct</strong></h3><p>Slices and structs can be combined as in slices and maps, the way they are used is similar, just add a [] sign before the data type at the time of declaration.</p><pre>type person struct {<br>    name string<br>    age  int<br>}<br><br>var allStudents = []person{<br>    {name: &quot;Wick&quot;, age: 23},<br>    {name: &quot;Ethan&quot;, age: 23},<br>    {name: &quot;Bourne&quot;, age: 22},<br>}<br><br>for _, student := range allStudents {<br>    fmt.Println(student.name, &quot;age is&quot;, student.age)<br>}</pre><h3>Method</h3><p>Methods are functions attached to types (can be structs or other data types). Methods can be accessed via object variables.</p><p>The advantage of methods over ordinary functions is that they have access to struct properties up to the private level (the access level will be discussed in more detail in the next chapter). Also, by using methods a process can be well encapsulated.</p><p>Application of method is slightly different than using a function. When the declaration, it is also determined who the owner of the method is. An example can be seen in the following code:</p><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>type CustomerOjol struct {</pre><pre>Name string</pre><pre>}</pre><pre>func (c CustomerOjol) sayHello() {</pre><pre>fmt.Println(&quot;Hello&quot;, c.Name)</pre><pre>}</pre><pre>func (co *CustomerOjol) GetName() string {</pre><pre>return co.Name</pre><pre>}</pre><pre>func (co *CustomerOjol) changeName(newName string) {</pre><pre>co.Name = newName</pre><pre>}</pre><pre>func main() {</pre><pre>ojol1 := CustomerOjol{&quot;Amad&quot;}</pre><pre>ojol1.sayHello()</pre><pre>ojol1.changeName(&quot;Luthfi&quot;)</pre><pre>ojol1.sayHello()</pre><pre>}</pre><h3>Method Pointer</h3><p>A method pointer is a method whose object variable is a pointer.</p><p>The advantage of this type of method is that, when we manipulate the value of another property that is still a struct, the value of that property will be changed to its reference. For more details, consider the following code.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>type student struct {<br>    name  string<br>    grade int<br>}<br><br>func (s student) changeName1(name string) {<br>    fmt.Println(&quot;---&gt; on changeName1, name changed to&quot;, name)<br>    s.name = name<br>}<br><br>func (s *student) changeName2(name string) {<br>    fmt.Println(&quot;---&gt; on changeName2, name changed to&quot;, name)<br>    s.name = name<br>}<br><br>func main() {<br>    var s1 = student{&quot;john wick&quot;, 21}<br>    fmt.Println(&quot;s1 before&quot;, s1.name)<br>    // john wick<br><br>    s1.changeName1(&quot;jason bourne&quot;)<br>    fmt.Println(&quot;s1 after changeName1&quot;, s1.name)<br>    // john wick<br><br>    s1.changeName2(&quot;ethan hunt&quot;)<br>    fmt.Println(&quot;s1 after changeName2&quot;, s1.name)<br>    // ethan hunt<br>}</pre><p>After execution of statement s1.changeName1(“jason bourne”), the value of s1.name does not change. Actually the value changes but only in the changeName1() method, the value of the reference in the object does not change. That’s why when the object is printed the value of s1.name doesn’t change.</p><p>Another feature of the method pointer is that the method itself can be called from a pointer object or an ordinary object.</p><pre>// method access from ordinary object variables<br>var s1 = student{&quot;john wick&quot;, 21}<br>s1.sayHello()<br><br>// method access from pointer object variable<br>var s2 = &amp;student{&quot;ethan hunt&quot;, 22}<br>s2.sayHello()</pre><p>Using the strings.Split() function</p><p>In this chapter there is a new function we use: strings.Split(). This function is useful for splitting a string using a self-defined separator. The result is an array containing a collection of substrings.</p><pre>strings.Split(&quot;ethan hunt&quot;, &quot; &quot;)<br>// [&quot;ethan&quot;, &quot;hunt&quot;]</pre><p>In the example above, the string “ethan hunt” is split using the space separator “ “. Then the result is an array containing 2 data, “ethan” and “hunt”.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e447b55dfe0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Week 3 as Golang Trainee at PT. Phincon-Part2]]></title>
            <link>https://medium.com/@luthfiarsyad68/week-3-as-golang-trainee-at-pt-phincon-part2-28ca7d386341?source=rss-60daae6a67b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/28ca7d386341</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Luthfiarsyad]]></dc:creator>
            <pubDate>Mon, 24 Oct 2022 02:48:43 GMT</pubDate>
            <atom:updated>2022-10-24T02:48:43.567Z</atom:updated>
            <content:encoded><![CDATA[<p>Previously we already know a function that must be made so that our program can run, namely the main function. Then what is its function, a function is a block of code that is intentionally created in a program so that it can be used over and over again. The way to create a function is very simple, only by using the keyword func then followed by the name of the function and the code block of the contents of the function. After creating a function, we can execute the function by calling it using the keyword function name followed by opening parenthesis, closing parenthesis.</p><p>The following is an example of using the function:</p><pre>package main</pre><pre>import &quot;fmt&quot;<br></pre><pre>func main() {</pre><pre>sayHello()</pre><pre>}</pre><pre>func sayHello() {</pre><pre>fmt.Println(&quot;Hello World!&quot;)</pre><pre>}</pre><p>There are 6 type of function we learn in Go Language in this bootcamp. There are Function Parameter, Function Return Value, Function Return Multiple Value, Function as Parameter, Variadic Function and Closure Function/Anonymous Function.</p><h3>Function Parameter</h3><p>Inside the function sometimes we need data from outside the function called parameters. We can add parameters in the function, it can be more than one Parameter is not mandatory, so we can create a function without parameters as we have previously created. But if we add parameters in the function, then when calling the function, we must enter data into the parameters.</p><p>This following is the example of Function Parameter:</p><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>func main() {</pre><pre>sayHello(&quot;Luthfi&quot;, &quot;Arsyad&quot;)</pre><pre>}</pre><pre>func sayHello(firstName string, lastName string) {</pre><pre>fmt.Println(&quot;Hello&quot;, firstName, lastName)</pre><pre>}</pre><p>Output of code above is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/161/1*644NBJuIUGOp4gJAJmHQNQ.png" /><figcaption>Output of function parameter</figcaption></figure><h3>Function Return Value</h3><p>Functions can return data. To tell that the function returns data, we must write the data type back from the function. If we declare the function with the return data type, then we must return the data in the function. To return data from a function, we can use the return keyword, followed by the data.</p><p>The following is an example of using the return value in a function:</p><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>func main() {</pre><pre>greet := getHello(&quot;Luthfi&quot;)</pre><pre>fmt.Println(greet)</pre><pre>}</pre><pre>func getHello(name string) string {</pre><pre>return &quot;Hello &quot; + name</pre><pre>}</pre><p>This following picture is output of code above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/106/1*1YPTfBCr274Fb4HZnerzDw.png" /><figcaption>Output of return value function.</figcaption></figure><h3>Function Return Multiple Value</h3><p>Functions can not only return one value, but also multiple values. To tell if a function returns multiple values, we have to write all the data types of its return values in the function.</p><p>Multiple return values must be captured by all values. If we want to ignore the return value, we can use the _ (underscore) sign.</p><p>The following is an example of using return multiple values in a function:</p><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>func main() {</pre><pre>x, y, z := GetFullName()</pre><pre>fmt.Println(x, y, &quot;berumur&quot;, z, &quot;tahun&quot;)</pre><pre>luasPersegi, kelilingPersegi := HitungPersegi(5)</pre><pre>luasLingkaran, kelilingLingkaran := HitungLingkaran(7)</pre><pre>luasPersegiPanjang, kelilingPersegiPanjang := HitungPersegiPanjang(8, 5)</pre><pre>fmt.Printf(&quot;Luas dari persegi adalah %v \nKeliling dari persegi adalah %v\n&quot;, luasPersegi, kelilingPersegi)</pre><pre>fmt.Printf(&quot;Luas dari lingkaran adalah %v \nKeliling dari lingkaran adalah %v\n&quot;, luasLingkaran, kelilingLingkaran)</pre><pre>fmt.Printf(&quot;Luas dari persegi panjang adalah %v \nKeliling dari persegi panjang adalah %v\n&quot;, luasPersegiPanjang, kelilingPersegiPanjang)</pre><pre>}</pre><pre>func GetFullName() (firstName string, lastName string, age int) {</pre><pre>firstName = &quot;Luthfi&quot;</pre><pre>lastName = &quot;Arsyad&quot;</pre><pre>age = 22</pre><pre>return</pre><pre>}</pre><pre>func HitungPersegi(sisi float32) (float32, float32) {</pre><pre>var keliling, luas float32</pre><pre>keliling = 4 * sisi</pre><pre>luas = sisi * sisi</pre><pre>return luas, keliling</pre><pre>}</pre><pre>func HitungLingkaran(jari float64) (float64, float64) {</pre><pre>var keliling, luas float64</pre><pre>phi := 3.14</pre><pre>keliling = phi * (2 * jari)</pre><pre>luas = phi * (jari * jari)</pre><pre>return keliling, luas</pre><pre>}</pre><pre>func HitungPersegiPanjang(Panjang, Lebar float64) (float64, float64) {</pre><pre>luas := Panjang * Lebar</pre><pre>keliling := 2 * (Lebar + Panjang)</pre><pre>return luas, keliling</pre><pre>}</pre><p>This following picture is output of code above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*ZlwvqdGmUPoaPQGNE6ZlAg.png" /><figcaption>This is output of multiple return value function.</figcaption></figure><h3>Function as Parameter</h3><p>Function itself can be declared and used as a parameter. It can be converted like we use a simple variable. To get to know better about this function, we can check it from this code below:</p><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>type Filter func(string) string</pre><pre>func main() {</pre><pre>var filter Filter = spamFilter</pre><pre>sayWithFilter(&quot;Anjing&quot;, filter)</pre><pre>sayWithFilter(&quot;Kambing&quot;, filter)</pre><pre>}</pre><pre>func spamFilter(text string) string {</pre><pre>if text == &quot;Anjing&quot; {</pre><pre>text = &quot;...&quot;</pre><pre>}</pre><pre>return text</pre><pre>}</pre><pre>func sayWithFilter(text string, filter Filter) {</pre><pre>say := filter(text)</pre><pre>fmt.Println(&quot;Say&quot;, say)</pre><pre>}</pre><p>This following is output of code above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/99/1*d6QQiHodHvAclzhp-asnpw.png" /><figcaption>Output Function as Params.</figcaption></figure><h3>Variadic Function</h3><p>Go adopts the concept of a variadic function or the creation of a function with an infinite number of similar parameters. Infinite means that the number of parameters inserted when calling the function can be any number.</p><p>Variadic parameters have similar properties to slices. The values of the parameters that are inserted are of the same data type, and are accommodated by only a variable. The way to access each data is also the same, using index.</p><p>The variadic parameter declaration is the same as the regular variable declaration method, the difference is that this type of parameter is added with three periods (…) right after writing the variable (before the data type). Later all values inserted as parameters will be accommodated by the variable.</p><p>Here is an example of its use:</p><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>func main() {</pre><pre>total := sumAll(10, 23, 45, 22, 5)</pre><pre>fmt.Println(&quot;Total dari semua elemen dijumlahkan&quot;, total)</pre><pre>numbers := []int{2, 35, 13, 256, 634, 11}</pre><pre>total_slices := sumAll(numbers...)</pre><pre>fmt.Println(&quot;Total slice dari varargs = &quot;, total_slices)</pre><pre>num := []int{2, 35, 13, 256, 634, 11, 10, 23, 45, 22, 5}</pre><pre>average, _, _ := average(num...)</pre><pre>fmt.Printf(&quot;Rata - rata dari data yang diinputkan adalah %v&quot;, average)</pre><pre>}</pre><pre>func sumAll(numbers ...int) int {</pre><pre>total := 0</pre><pre>for _, v := range numbers {</pre><pre>total += v</pre><pre>}</pre><pre>return total</pre><pre>}</pre><pre>func average(numbers ...int) (float64, int, int) {</pre><pre>var total int</pre><pre>var length = len(numbers)</pre><pre>for _, v := range numbers {</pre><pre>total += v</pre><pre>}</pre><pre>avg := float64(total) / float64(length)</pre><pre>return avg, length, total</pre><pre>}</pre><pre>func nilaiSiswa(name string, score ...int) (string, int) {</pre><pre>totalScore := 0</pre><pre>for _, v := range score {</pre><pre>totalScore += v</pre><pre>}</pre><pre>return name, totalScore</pre><pre>}</pre><p>This following picture is output of code above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*L1DHAhTvvSGu139G8gxE5Q.png" /><figcaption>Output of Variadic Function.</figcaption></figure><h3>Closure Function/Anonymous Function.</h3><p>The definition of a closure is a function that can be stored in a variable. By applying these concepts, we can create functions within functions, or even create functions that return functions.</p><p>Closure is an anonymous function or function without a name. Usually used to wrap a process that is only used once or used on certain blocks.</p><p>This following code is example of anonymous function:</p><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>func main() {</pre><pre>blacklist := func(name string) bool {</pre><pre>return name == &quot;Anjing&quot;</pre><pre>}</pre><pre>registerUser(&quot;Umar&quot;, blacklist)</pre><pre>}</pre><pre>func registerUser(name string, blacklist func(string) bool) {</pre><pre>if blacklist(name) {</pre><pre>fmt.Println(&quot;Anda di blokir karena menggunakan nama anjing&quot;)</pre><pre>} else {</pre><pre>fmt.Println(&quot;Welcome&quot;, name)</pre><pre>}</pre><pre>}</pre><p>This following picture is output of anonymous function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/105/1*oujjDIXVlX9fHv46VvvJKQ.png" /><figcaption>This is output of code above.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28ca7d386341" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Week 3 as Golang Trainee at PT. Phincon-Part1]]></title>
            <link>https://medium.com/@luthfiarsyad68/week-3-as-golang-trainee-at-pt-phincon-part1-f20c43edd8?source=rss-60daae6a67b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/f20c43edd8</guid>
            <category><![CDATA[golang-tutorial]]></category>
            <dc:creator><![CDATA[Luthfiarsyad]]></dc:creator>
            <pubDate>Mon, 24 Oct 2022 01:24:54 GMT</pubDate>
            <atom:updated>2022-10-24T01:24:54.768Z</atom:updated>
            <content:encoded><![CDATA[<p>Array is a group of data with a same datatype that is stored in a variable. To make an array, we need to use brackets and declare the data type like this code below.</p><pre>variable := […]dataType{}</pre><p>To use an array, we have to make sure we declare the size of the array like this</p><pre>variable := [8]dataType{value}</pre><p>If we do not want to declare it, we can actually change it to a dynamic size array by using “…” like code shown below</p><pre>variable := [...]dataType{value}</pre><p>First thing we do are exercising on array by making array inverted from its original . This is how my code are.</p><pre>s := [...]string{&quot;Umar&quot;, &quot;Syifa&quot;, &quot;Ilham&quot;, &quot;Umar A&quot;, &quot;Syifa S&quot;, &quot;Gres&quot;}</pre><pre>oldAr := s</pre><pre>for i, j := 0, len(s)-1; i &lt; j; i, j = i+1, j-1 {</pre><pre>oldAr[i], oldAr[j] = oldAr[j], oldAr[i]</pre><pre>}</pre><pre>ar := s</pre><pre>fmt.Println(oldAr)</pre><pre>fmt.Println(ar)</pre><p>The code above will make an output like picture below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*p8y9fOXxxpmNVW-KT8R1pg.png" /><figcaption>This is the output of my inverting array code.</figcaption></figure><p>After learning array we are exercising about it.</p><pre>// Exercise 1</pre><pre>months := […]string{“Januari”, “Februari”, “Maret”, “April”, “Mei”, “Juni”, “Juli”, “Agustus”, “September”, “Oktober”, “November”}</pre><pre>fmt.Println(months, “\n”)</pre><p>This first exercise is to make an array consist of months in indonesian language😁. The output of this code is like this pic below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*TDb8tzX6uIjmnTysE-UjRw.png" /><figcaption>This is the output of exercise code 1 above.</figcaption></figure><p>After making that exercise we are continuing with the second one, its</p><pre>// Exercise 2</pre><pre>mult := [2][3]int{{1, 2, 3}, {4, 5, 6}}</pre><pre>fmt.Println(mult, &quot;\n&quot;)</pre><p>This code is about outputing multidimensional array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*A-poYR1crwY6ndFX_369Zw.png" /><figcaption>This is output of exercise 2.</figcaption></figure><p>After that we exercise about combining array index, this is the code that i wrote down.</p><pre>// Exercise 3</pre><pre>array1 := []int{1, 2, 3, 4}</pre><pre>array2 := [...]int{5, 6, 7, 8}</pre><pre>array3 := array1</pre><pre>for index, _ := range array2 {</pre><pre>array3 = append(array3, array2[index])</pre><pre>}</pre><pre>fmt.Println(&quot;Array gabungannya adalah:&quot;, array3, &quot;\n&quot;)</pre><p>This is the output of code above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/155/1*WnjMN7HMJ-WUSB-JGtKqUw.png" /><figcaption>Output of exercise 3</figcaption></figure><p>After that we are learning about making odd even for from</p><pre>// Exercise 4</pre><pre>even := []int{}</pre><pre>odd := []int{}</pre><pre>initArr := [...]int{1, 2, 3, 4, 5, 6, 7, 8}</pre><pre>for i := 0; i &lt; len(initArr); i++ {</pre><pre>if initArr[i]%2 == 0 {</pre><pre>even = append(even, initArr[i])</pre><pre>} else {</pre><pre>odd = append(odd, initArr[i])</pre><pre>}</pre><pre>}</pre><pre>fmt.Println(&quot;Odd array  :&quot;, odd)</pre><pre>fmt.Println(&quot;Even array :&quot;, even)</pre><p>Output of the code above is like the picture below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*lBHInNMFC10OEuxFn-yfVw.png" /><figcaption>Even odd output from array.</figcaption></figure><p>After that we are making an array consist of details of trainers and trainee in Go developer trainee. We are needed to make loops for every index of the array. Code that i wrote is like show below.</p><pre>// Exercise 5</pre><pre>details := [...][]string{{&quot;Umar Bawazir&quot;, &quot;21&quot;, &quot;Bekasi&quot;}, {&quot;Aan&quot;, &quot;18&quot;, &quot;Bekasi&quot;}, {&quot;Lutfi &quot;, &quot;20&quot;, &quot;Jakarta&quot;}, {&quot;Wira &quot;, &quot;24&quot;, &quot;Semarang&quot;}}</pre><pre>fmt.Println(&quot;\n============================&quot;)</pre><pre>for i, _ := 0, 0; i &lt; 1; i++ {</pre><pre>for _, v1 := range details {</pre><pre>i += 0</pre><pre>fmt.Println(&quot;Nama   :&quot;, v1[0])</pre><pre>fmt.Println(&quot;Umur   :&quot;, v1[1])</pre><pre>fmt.Println(&quot;Alamat :&quot;, v1[2])</pre><pre>fmt.Println(&quot;============================&quot;)</pre><pre>}</pre><pre>}</pre><p>Output of code above is shown in screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*EbYM4-gH0NfhtH4fRvFsGQ.png" /><figcaption>Output of code above.</figcaption></figure><p>After doing some exercise with array, we are continuing for the next material. We are learning about slice on Go language. Slicing is basically an element that refers to array. to declare a slice we can actually use like code below:</p><pre>slice := []int{value}</pre><p>The only difference that slice and an array make was there are no params included inside the length of the array, not even a triple dots. The details of how difference them both are, we can see at my code below.</p><pre>names := [...]string{&quot;Umar&quot;, &quot;Bawazir&quot;, &quot;Reza&quot;, &quot;Ahmad&quot;, &quot;Nabila&quot;}</pre><pre>fmt.Println(names)</pre><pre>namesA := []string{&quot;Umar&quot;, &quot;Bawazir&quot;, &quot;Reza&quot;, &quot;Ahmad&quot;, &quot;Nabila&quot;}    //slice</pre><pre>namesB := [6]string{&quot;Umar&quot;, &quot;Bawazir&quot;, &quot;Reza&quot;, &quot;Ahmad&quot;, &quot;Nabila&quot;}   //array</pre><pre>namesC := [...]string{&quot;Umar&quot;, &quot;Bawazir&quot;, &quot;Reza&quot;, &quot;Ahmad&quot;, &quot;Nabila&quot;} //array</pre><pre>fmt.Println(namesA)</pre><pre>fmt.Println(namesB)</pre><pre>fmt.Println(namesC)</pre><p>From the code above we can make a difference in how slice and array is written in Go. Output of code above can be seen in pic below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*0D2iAcLjTuVP_PYW4c8eSQ.png" /><figcaption>On the third row as we can see its like there is a space, its because the index is not fulfilled.</figcaption></figure><p>Slices itself used for manipulating array like code shown below:</p><pre>names := [...]<strong>string</strong>{&quot;Umar&quot;, &quot;Bawazir&quot;, &quot;Reza&quot;, &quot;Ahmad&quot;, &quot;Nabila&quot;}</pre><pre>var slice = names[2:4]</pre><pre>fmt.Println(slice)</pre><pre>fmt.Println(&quot;Panjang slice&quot;, len(slice))</pre><pre>fmt.Println(&quot;Kapasitas slice&quot;, cap(slice))</pre><pre>fmt.Println(names)</pre><pre>slice = append(slice, &quot;Akhyar&quot;)</pre><pre>slice = append(slice, &quot;Syifa&quot;)</pre><pre>slice = append(slice, &quot;Arie&quot;)</pre><pre>slice = append(slice, &quot;Aan&quot;)</pre><pre>fmt.Println(slice)</pre><pre>fmt.Println(names)</pre><p>For code above we can see that it is a slice and append of an element to an array. Picture below shown what is the output of my code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*Lo6HNMwZHz0NatKfa39FUw.png" /><figcaption>Output of slice code.</figcaption></figure><p>Take notes that slice is a reference data type that always refers to the real array, to cut that refers we can actually exceed the cap of referred array and it automatically make a new array like it shown in the 5th line of output slice above.</p><p>There are 4 crucial function that is used inside a slice. There are len(), cap(), append(), copy(). Each of every function are used for:</p><ul><li>len(slice) = To count how many elements inside the array.</li><li>cap(slice) = To count how many element can the array holds.</li><li>append(slice, value1, value2, value…) = To insert and element to an array.</li><li>copy(destination slice, array/slice) = To copy a precise element of array to a new array.</li></ul><p>Making slice with advance declaration are using make function. For the easy example we can see it on my simple code below:</p><pre>newSlice := make([]<strong>string</strong>, 2, 5)</pre><pre>newSlice[0] = “Luthfi”</pre><pre>newSlice[1] = “Arsyad”</pre><p>as we can see the code above uses make([]dataType, length, capacity). For that we uses string to holds name and insert it inside the newSlice with a hard code to the index itself using slice[index]=value.</p><p>Map is what we are learning after we finish discussing about array with basic</p><pre>var persons Persons <em>// var persons []map[string]string; membuat slice</em></pre><pre>var person Person = Person{</pre><pre>&quot;name&quot;:    &quot;Umar&quot;,</pre><pre>&quot;address&quot;: &quot;Bekasi&quot;,</pre><pre>}</pre><pre>persons = append(persons, person)</pre><pre>var person2 Person = Person{</pre><pre>&quot;name&quot;:    &quot;Aaan&quot;,</pre><pre>&quot;address&quot;: &quot;Jakarta&quot;,</pre><pre>}</pre><pre>persons = append(persons, person2)</pre><pre>fmt.Println(persons)</pre><pre>for _, j := range persons {</pre><pre>fmt.Println(j[&quot;name&quot;])</pre><pre>}</pre><pre>fmt.Println(person)</pre><pre>fmt.Println(per son[&quot;name&quot;])</pre><pre>fmt.Println(person[&quot;address&quot;])</pre><p>This code is making a slice map that consist of maps that holds data of name and address of person, and code above is teaching us to append data to slice map, and iterate it to make the output as shown as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*uMO6GRCA3Dhj-n_AMYxv7A.png" /><figcaption>Output of slice map code.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f20c43edd8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Week 2 Bootcamp Golang at PT. Phincon]]></title>
            <link>https://medium.com/@luthfiarsyad68/week-2-bootcamp-golang-at-pt-phincon-a154a6b8ef27?source=rss-60daae6a67b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/a154a6b8ef27</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[training]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <dc:creator><![CDATA[Luthfiarsyad]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 06:21:28 GMT</pubDate>
            <atom:updated>2022-10-12T06:26:37.923Z</atom:updated>
            <content:encoded><![CDATA[<h3>Week of branching and looping.</h3><p>Like the subtitle above said, at first we are starting to review what are doing and what we learn about parts of Go Language from previous week. Although its just some review, for me this kind of review is what we need to help us always memorize what are the things we must know (basics) of Go Language.</p><p>After we do the review, we are taught about how to use arithmetic operators. Usage of arithmetic operators that most likely used for if conditions like this picture below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*5Qt4ev6beEufZz1huxikRg.png" /><figcaption>Arithmetics example.</figcaption></figure><p>As we can see how to use these kind of operators like</p><ul><li>+</li><li>-</li><li>*</li><li>/</li><li>%</li><li>++</li><li>— — these are the operator used for value = value — 1</li></ul><p>We are talking about how to use those operators and after that we learn how to use if statements in Go Language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*8GmTgsPUYeZux2NpuPS11Q.png" /><figcaption>This is the example of operators in use</figcaption></figure><p>Just a little explanation about the result, that app will sum current value of i with 10 and set i variable with the value. After we learn about the simple way of using an operator, we continue learning logical operators as it shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*C7nTuZA1iPtxSY9CeYrbSQ.png" /><figcaption>Example of logical operators in use.</figcaption></figure><p>For most cases, usage of operators are crucial on branching purposes. mostly it is used for making conditions inside a branching. After learning about logical operators we continue learning by discussing about relational operators, like code i wrote down below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*tMmJzvUOqgvk4rvOcKz1Zw.png" /><figcaption>Example use of relational operators in a code.</figcaption></figure><p>For those who have known programming, you guys might think this is very basic and easy to use. The syntax we use for branching is as same as many other language. for instance this is what we do at first day:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*yAXw-ULPqdL-7Tee3I3MAw.png" /><figcaption>This is a simple if statement with use of function as the improvements.</figcaption></figure><p>On my code above i want to make 2 things with if statement, i want to know if the name is listed or not and i want to make a function for counting length of the given parameter are.</p><p>After finish discussing about use of if statement, we continue to learn about switch case. The code itself can we see as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*luWsLcSOcYRh9TG1NyqzbQ.png" /><figcaption>Example of switch uses in a code.</figcaption></figure><p>We use switch case mostly as same as if else, in the picture above we can actually see what switch will be look like (looks like a C or C++ syntax), the different thing we can use in go is usage of fallthrough in a code. Fallthrough used in a code for running every condition in for and yields every output that suits the condition.</p><p>Today i learn about for loops in Go Language. Prior to this, i already learned for-loops in C++ and the main thing that make Loops in Go distinct from what i learn before is there is no other loops beside for, there are no do-while or while-do loops. So, below are the code i wrote down about for loops in Go:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F7pifZ_s4ROxtdBURBkNBw.png" /><figcaption>Example of For Loops in Go.</figcaption></figure><p>There are many things of for in go, like we can see above there are Go For, Infinite Go For, Native For(Like C++ or C) and For Range. Those kind of loops are loops in Go that i learned in this Bootcamp. If you would like to see what task i already make during this week, you guys can open <a href="https://medium.com/@luthfiarsyad68/bootcamp-go-language-pt-phincon-exercise-week-2-88a0e5d215c6">this</a>, Thanks for reading this and see you in anoter day! 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a154a6b8ef27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bootcamp Go Language PT. Phincon Exercise Week 2]]></title>
            <link>https://medium.com/@luthfiarsyad68/bootcamp-go-language-pt-phincon-exercise-week-2-88a0e5d215c6?source=rss-60daae6a67b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/88a0e5d215c6</guid>
            <category><![CDATA[training]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Luthfiarsyad]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 06:20:11 GMT</pubDate>
            <atom:updated>2022-10-12T06:20:11.713Z</atom:updated>
            <content:encoded><![CDATA[<p>These are exercise of what we do on week 2.</p><p>My first exercise task was making 3 if statement and switch case, first one must have an arithmetic operators or about calculations, second one must have multiple condition if, and the third one is up to us. So after taking 2 sip of coffee, i decided to make absolute odd subtract calculator 😬. These are the codes of my program:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*ieBBlGhA1GYcpyty7mzgYQ.png" /><figcaption>Odd Calculator Subtraction Calculator Function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qr91aTKrxZgDvVf1QLfAPg.png" /><figcaption>This is how to use function inside main function looks like.</figcaption></figure><p>As we can see together on that calculator there will be no negative value. After making this program, i made an app for odd descending sort calculator, so we can actually get bigger value always in left.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*KcTM2zHfUbOYzxPA4bsfsg.png" /><figcaption>This is what i make about odd descending sort calculator.</figcaption></figure><p>Last but not least, we make a static app to log in, just to make it fast and easy to build and implement if statement with rather complex but easy to build app like this code below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*VGZwoVcJpRBweEWl89f9-Q.png" /><figcaption>This is my third exercise code that i made.</figcaption></figure><p>On switch cases example i made a calculator of 2 variables, picture below shows what i wrote down for that program:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*KXRuCFBHoQVvcD7QoRl6vw.png" /><figcaption>This is a program of basic calculator with 2 variable.</figcaption></figure><p>The program i made was for a dynamic input of choice, so we can actually choose between addition, subtraction, multiplication and division. After that i made a program about categorizing what are 2 value are, and which one is bigger. Below are the program that i wrote down:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*v7UHwrTBZaGCvY8FKEDPrw.png" /></figure><p>And last but not least i made a program about switching names that returns the position of people that is listed on PT. Phincon right now, below are the code that i wrote:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*03AriXe0-B6xD5LKI-hZNg.png" /></figure><p>After we do exercise about branching, we continue to learn about for loops in Go, and we are making exercise about few things such as this code below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*xSS73BORswHo51K_2lXCdw.png" /><figcaption>Code of descending loop.</figcaption></figure><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*pvDFRdgv9ywUKZqRnYxKCw.png" /><figcaption>Output of descending loop.</figcaption></figure><p>Exercise 1 is about loop of 10 to 0 (Descending)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*Zu-GXZRmGoGAYMPrdabHQA.png" /><figcaption>Code of ascending loop of multiple of five.</figcaption></figure><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*oHr5HupJVeD8t5QKy3KS-g.png" /><figcaption>Output of ascending loop of multiple of five.</figcaption></figure><p>Code above are code for loop that multiple by five in every iterations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*xpQgmEanPThtKfMV7zUPnw.png" /><figcaption>Code for Matrix.</figcaption></figure><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*UQJywEkyxB9QcQLAaghwhg.png" /><figcaption>Output for Matrix.</figcaption></figure><p>This code above is for making matrix using for loops in Go language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*sYIOqwX8fhGWaT3VJcR5Xw.png" /><figcaption>Code of simple triangle that prints per column.</figcaption></figure><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*3DKnh8Jo4Dpt7gQVUMfWFQ.png" /><figcaption>Output of simple triangle that prints per column.</figcaption></figure><p>This code is an exercise for us to make a right triangle that prints their own column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*A0wgJPcOejFXnF2HxBSKtA.png" /><figcaption>Code of simple triangle with condition.</figcaption></figure><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*wUsfLj4TndSUYy5xnai5jg.png" /><figcaption>Output of simple triangle with condition.</figcaption></figure><p>The last but not least, we are making right triangle with same concept like previous exercise, but we are making it with every odd row only prints odd number, and as well as even row. thats what we’re making on the exercise.</p><p>After doing exercise, i was given a task to make 3 program using for-loops. This code below are my code for every task that i have been given:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*UL73tLYWbSFnSF4fWMLJpg.png" /><figcaption>Simple Code of FizzBuzz quizz test</figcaption></figure><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*HS-8ccIf19xf0J_7yJm-NA.png" /><figcaption>Fizzbuzz Output.</figcaption></figure><p>This code is normal code for IT recruitment purposes. that’s why i am making this code, i already do this in every H****rRank test. Thank you H****rRank AHAHAHAHA. Anyways, on the next for i make a calculator program to print out an odd or even numbers iterable with upper and lower limit that is dynamically can change. Below are my code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*c7ESC7zJfxqeWCR1GkYT2g.png" /><figcaption>Odd Even iterable code.</figcaption></figure><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*wXP6-yi_X8yPgyS63ZQ6TQ.png" /><figcaption>Output of Even Odd number iterable.</figcaption></figure><p>The last program that i made is making dynamic input of square maker (i name it by myself🤣). Below are my source code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*ZAiDrgxg6TaYEKTUKICzCw.png" /><figcaption>Source code of Square drawer.</figcaption></figure><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*Xk9cUXAlo7yPFyK88QSqtQ.png" /></figure><p>Thats what i made this week, i hope you guys love to see this and make a fun review about this articles, thanks and see you aroun coders 👋.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88a0e5d215c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[First Week of Go Bootcamp at PT. Phincon]]></title>
            <link>https://medium.com/@luthfiarsyad68/first-week-of-go-bootcamp-at-pt-phincon-10885df87752?source=rss-60daae6a67b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/10885df87752</guid>
            <category><![CDATA[training]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[personal-blog]]></category>
            <category><![CDATA[training-and-development]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Luthfiarsyad]]></dc:creator>
            <pubDate>Thu, 06 Oct 2022 07:57:48 GMT</pubDate>
            <atom:updated>2022-10-07T04:14:58.763Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*95UFl3jZdR96rHfO4ghjMg.jpeg" /><figcaption>Golang trainee team with Mr. Umar as the trainer in the middle.</figcaption></figure><h3>Introduction</h3><p>First day, we are introduce to Mr. Umar Bawazier by Ms. Asri as the assistant board of director at PT. Phincon. We learn about how golang was made by Rober Griesemer, Rob Pike, and Ken Thompson and released as an open source at 2009 and popularly used at 2011 when Docker was made using this programming language. Many new techs right now uses go programming language like Kubernetes, Prometheus, CockroachDB, etc. And currently many tech companies in Indonesia uses Go as their choice of programming language to make Backend API for Microservices.</p><p><strong>Why Golang?</strong></p><p>Because, Go is an open source programming language supported by Google, Easy to learn and get started with, Built in concurency and a robust standard library, and last but not least Growing ecosystem of partners ,communities and tools.</p><h3>Go Installation</h3><p>The first material learned is how to installing Go. First of all go straight to Go Website and open up the <a href="https://go.dev/doc/install">download link</a> and choose the version of download that your OS uses guys, i personally use Windows 10, thats why i you guys see the “Download Go for Windows”.</p><figure><img alt="This is screenshot of the download page." src="https://cdn-images-1.medium.com/max/937/1*7erWpzYNQseTNw87vm_Xhw.png" /><figcaption>This is the download page of Go, we have to have Go installed for the precondition to go for this bootcamp, of course it is because im attending Golang Developer Bootcamp 😂.</figcaption></figure><p>After downloading Go, we have to Install Go by opening the installer that we already downloaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mqy1YyhU7_ptOZQ0V7ruLQ.png" /><figcaption>This is the page that we are facing when opening go installer.</figcaption></figure><p>Next step, what we need is just to follow the installation steps. By finishing all the steps, you are now officially have Go in your PC guys congrats!</p><h3>Coding Parts 😍</h3><p>First step of all the coding is, you have to open our preferred Code Editor, i personally uses Visual Studio Code. Second Step is try to make a file name it as main.go as our first main file and type down this code guys, to check if we already installed Go Language perfectly as this picture below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*vHjv7Xti4hKhtbS3zBBrQQ.png" /><figcaption>This is the basic code to test the Hello World!</figcaption></figure><p><strong>Golang Basic Commands</strong></p><ul><li>go mod init, this is used for initializing our project</li><li>go run, this is used for executing program file that have .go extension</li><li>go build, this is used for compiling file in the folder to become a binary file such is .exe for windows</li><li>go get, this command is used for downloading package that we want to use for project that we take</li><li>go mod tidy, this command used for validating dependencies that is used for currently running project, for download the package or to clean up the package that is not used at all in our project (I personally recommend to not use this untill your project is final already).</li><li>go mod vendor, this is used for vendoring project.</li></ul><p>Further action after we typed down the code is if we uses Visual Studio Code, we open up terminal by pressing ctrl + ~ . after that we type down go run &lt;File Name&gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*LTr3Y6OQpDGlRpH6F9pTaA.png" /><figcaption>This is How we run Go scripts.</figcaption></figure><p>After this step our trainer is telling us what is variable, and the thing that we know guys, theoretically variable is just some sort of storage to store a value inside some imaginary place. It’s like we have to store apple, lemonade, pear at a same time, we need a variable to store those fruits. This is the basic concept of variables. These are the code you guys can try btw:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*ysJQmazpYVlGRjtZGi3buw.png" /><figcaption>Variable Declarations and how we call it.</figcaption></figure><p>After discussing about variables we are going further to how data type and constant works in Go Language, mostly if you guys already uses other programming language, we are using the same concept as C mostly but the syntax is not really far from other programming language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*e6NgNuWLFHzyKVbwg6d6bQ.png" /><figcaption>Go syntax that looks like C</figcaption></figure><p>C Programming uses print f as print format, and thats how Go Programing Language works too as it shown above. and we can see other type of use of variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*pMyVWEQRniqBrPu-mLnv8w.png" /><figcaption>This is the screenshot of how we uses variable.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*iewytVjAvuH_R3ixaoHyRw.png" /><figcaption>This is the screenshot of how we uses variable.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*rc_84SFDHUQHYeE7rHGPCw.png" /><figcaption>This is the screenshot of how we uses variable.</figcaption></figure><p>After we try using variable in so many cases as above, we try to apply to use basic function as len and uses “string”[number]. Len uses for counting how long the and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*B0T9gaOKv-H-MjsfNIYEBg.png" /><figcaption>Example of how we use the string functions.</figcaption></figure><p>Number data type, there are 2 things of number data type:</p><ul><li>Integer</li><li>Floating Point</li></ul><p>Integer data type have minimum and maximum size of its value, as it written below:</p><ul><li>int8 from -128 to 127</li><li>int 16 from -32768 to 32767</li><li>int32 from -214783648 to 2147483647</li><li>int64 from -9223372036854775808 to 9223372036854775807</li></ul><p>Unlike integer, unsigned integer datatype was made without any minus value at its minimum size of value, so the data size value would be like shown below:</p><ul><li>uint8 from 0 to 255</li><li>uint 16 from 0 to 65535</li><li>uint32 from 0 to 429567295</li><li>uint64 from 0 to 18446744073709551615</li></ul><p>Below is how we use number data type in a coding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*G0mwhEc7ZiqBD2a0wlQHqw.png" /><figcaption>This is how we use number data type in a golang code.</figcaption></figure><p>Boolean was the next material that we are discussing after that, we discuss how boolean can be used in Go. This is how the code will look like if we use want to implement boolean:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*f_2OXooggveUwyfO4x-xlw.png" /><figcaption>Implementation of Boolean.</figcaption></figure><p>After that we learn to use constant. Const or constant uses for variable that is fixed and dont want to be changed anymore. My mentor said it is actually used for JSON mostly, because the return value of JSON should not need anymore changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*_XoDANT2o3BRxTN8aPHPVA.png" /><figcaption>This is how we declare a multiple constant.</figcaption></figure><p>After learning about how to use constant we learn how to convert data type like we can see it below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*GfBZUFOAqhC95N-0stbsBA.png" /><figcaption>This is how we use conversion using native Go function.</figcaption></figure><p>Last but not least in this week we learn about Type Declaration. Type declaration is having a power to remake data type to become a new kind of data type. Its like you guys making your own aliases. This declarations usually used for making alias for data types that already exist for making things easier and clearer for programmer itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*3fplhQCxGeC-RN7I4hRQwA.png" /><figcaption>Example of how to use type declarations.</figcaption></figure><p>Those are the things that i personally learn in the first week in PT. Phincon as a Golang Developer. Mostly we had a great discussion on what projects that might come for golang developers in this company. Thanks for reading this guys! i hope it helps you guys at learning basics of Golang.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10885df87752" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>