<?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 Hamza Burakhan Göç on Medium]]></title>
        <description><![CDATA[Stories by Hamza Burakhan Göç on Medium]]></description>
        <link>https://medium.com/@hamzaburakhan?source=rss-bd0c3a585231------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Hamza Burakhan Göç on Medium</title>
            <link>https://medium.com/@hamzaburakhan?source=rss-bd0c3a585231------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 05:19:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hamzaburakhan/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[Handling UTC Date Formats in Go]]></title>
            <link>https://medium.com/trendyol-tech/handling-utc-date-formats-in-go-3e45bc093aaa?source=rss-bd0c3a585231------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e45bc093aaa</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[datetime]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[utc]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Hamza Burakhan Göç]]></dc:creator>
            <pubDate>Thu, 02 Feb 2023 06:22:27 GMT</pubDate>
            <atom:updated>2023-03-06T08:49:38.112Z</atom:updated>
            <content:encoded><![CDATA[<p>As Trendyol Indexing Team, we recently completed the development of a Go project that collected data from multiple microservices. However, We encountered an issue where the incoming date formats were causing parse errors. After investigating the issue, we found that the data was not always sent in the same layout. In this article, we’ll take a look at the challenge we faced and how we solved it as a team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Dgd56W6kfoOSpE64" /><figcaption>Photo by <a href="https://unsplash.com/@cookiethepom?utm_source=medium&amp;utm_medium=referral">Cookie the Pom</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In the project, there is a function that converts the given date to a time object. Unfortunately, we faced an issue where some of the dates were causing parse errors. After inspection, we found that the incoming date format was different from the expected format. The incoming format was as follows:</p><ul><li>2023–01–31T11:50:42.12Z</li><li>2023–01–31T11:50:42.1Z</li></ul><p>After reviewing the code, we discovered that it was expecting a format with three digits of milliseconds after the seconds and the letter “Z”. Only the following format was parsing successfully</p><ul><li>2023–01–31T11:50:42.129Z</li></ul><p>Old Function:</p><pre>const UtcDateFormat = &quot;2006-01-02T15:04:05.000Z&quot;<br>func ParseToTimeWithUtc(date string) (time.Time, error) {<br>   d, err := time.Parse(UtcDateFormat, date)<br>   if err != nil {<br>      logger.Logger().Error(fmt.Sprintf(&quot;%s can not be parse msg %s&quot;, date, err.Error()))<br>      return time.UnixMilli(0), err<br>   }<br>   return d, nil<br>}</pre><p>We needed a function that could parse all three incoming dates. To achieve this, we decided to use a <strong>standard</strong> instead of a static format. In Java, we had been using the <strong>ISO 8601</strong> standard. But, we couldn’t find a similar layout defined in the ‘time’ package of Go. A little research led us to the RFC 3339 layout, which met our requirements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JzASl07ahDU_RoZj4Lr2RQ.png" /><figcaption>RFC3339 vs ISO8601</figcaption></figure><p>Therefore, we resolved the error by passing the value<strong> ‘time.RFC3339’</strong> to the parse function in our code block. With this change, our function is now able to parse all three incoming dates.</p><pre> d, err := time.Parse(time.RFC3339, date)</pre><p>We also updated the unit test as shown below. We wrote the test using the table test style. You can reach my friend’s article describing our team’s experience with table testing from <a href="https://medium.com/trendyol-tech/unit-test-strategies-with-go-b892c2ccb61a">this link.</a></p><pre> tests := []struct {<br>  date     string<br>  expected time.Time<br>  wantErr  assert.ErrorAssertionFunc<br> }{<br>  {&quot;2022-03-09T03:30:11.123Z&quot;, time.Date(2022, time.March, 9, 3, 30, 11, m(123), time.UTC), assert.NoError},<br>  {&quot;2022-03-09T03:30:11.12Z&quot;, time.Date(2022, time.March, 9, 3, 30, 11, m(120), time.UTC), assert.NoError},<br>  {&quot;2022-03-09T03:30:11.1Z&quot;, time.Date(2022, time.March, 9, 3, 30, 11, m(100), time.UTC), assert.NoError},<br>  {&quot;2022-03-09T03:30:11Z&quot;, time.Date(2022, time.March, 9, 3, 30, 11, m(0), time.UTC), assert.NoError},<br>  {&quot;2022-03-09T03:30:11.816253Z&quot;, time.Date(2022, time.March, 9, 3, 30, 11, 816253000, time.UTC), assert.NoError},<br>  {&quot;2022-03-09T03:30:11.Z&quot;, time.UnixMilli(0), assert.Error},<br>  {&quot;2022-03-09T03:30:11&quot;, time.UnixMilli(0), assert.Error},<br>  {&quot;invalid&quot;, time.UnixMilli(0), assert.Error},<br> }</pre><p>If you’re interested in joining our team, you can apply for <a href="https://jobs.lever.co/trendyol/4bf7e1b0-1e26-4a2f-9208-f156b8437e8c?lever-via=dSAoWKg-1Z">the role of backend developer</a> or any of our current <a href="https://jobs.lever.co/trendyol?lever-via=dSAoWKg-1Z">open positions</a>.</p><p><strong>References:</strong></p><ul><li><a href="https://ijmacd.github.io/rfc3339-iso8601/">https://ijmacd.github.io/rfc3339-iso8601/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e45bc093aaa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/handling-utc-date-formats-in-go-3e45bc093aaa">Handling UTC Date Formats in Go</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Concurrency with Goroutines]]></title>
            <link>https://medium.com/trendyol-tech/concurrency-with-goroutines-272a4799df3f?source=rss-bd0c3a585231------2</link>
            <guid isPermaLink="false">https://medium.com/p/272a4799df3f</guid>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[goroutines]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[future]]></category>
            <dc:creator><![CDATA[Hamza Burakhan Göç]]></dc:creator>
            <pubDate>Mon, 16 Jan 2023 12:40:40 GMT</pubDate>
            <atom:updated>2023-05-23T18:21:44.554Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will talk about a small go library that we wrote to make it easier to use goroutine and to write clear code. Let’s see how this package came out.</p><p>As Trendyol Indexing Team, we had a project written in Scala that collected data from many microservices. To reduce the workload of the current team and the complexity of the project, we have formed the Indexing Offer team, which I am also part of.</p><p>My team will be responsible for price and stock-related business. This means that the new team will work with 8 microservices and 4 different teams for now. Of course, with this division, we moved not only an API but also the consumers of the relevant business to the new team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nkwfcv0hDDPBqK-H7h2KIg.jpeg" /></figure><p>We have several APIs written in Go, and we have observed that Go performs well in terms of boot time, memory usage, and CPU usage. We get high throughput from these APIs with few resources. As a result, we have decided to write our new API using Go.</p><p>Let’s get back to our main topic. We have the following situations when sending requests to services.</p><ul><li>We need to split the request into smaller chunks and send them.</li><li>Some services are independent of each other, so we can send parallel requests.</li></ul><p>We could easily do this with Future.sequence and for-yield in Scala</p><p>Example in Scala</p><pre>// Future.sequence<br>def ChunkRequestAndGetAll(ids: Array[String]): Future[Seq[String]] = {<br>  Future.sequence(ids.grouped(chunkSize).map(chunkedIds =&gt; {<br>    Future {<br>      APICall(chunkedIds)<br>    }<br>  }).toSeq)<br>}<br><br>// for-yield<br>def ForYieldExample() = {<br>  val f1: Future[String] = Future {APICall(&quot;call&quot;)}<br>  val f2: Future[Int] = Future {AnotherAPICall()}<br><br>  val result = for {<br>    r1 &lt;- f1<br>    r2 &lt;- f2<br>  } yield (anyFunc(r1, r2))<br><br>  Await.result(result, 5.seconds)<br>}</pre><p>In our previous go projects, We didn’t have such a requirement. We were going to see how we can do that in Go while doing this project.</p><p><strong>Smaller chunks and sending them</strong></p><p>This example demonstrates how to split a request and send it in parallel. The results of all parallel operations are collected in a list, and the function returns an error if any operation fails.</p><pre>func ChunkRequestAndGetAll(ids []string) ([]string, error) {<br> var chunkOfIds [][]string = chunk(ids, chunkSize)<br> <br> ch := make(chan result, len(chunkOfIds))<br> for i := range chunkOfIds {<br>  chunkedIds := chunkOfIds[i]<br>  go func() {<br>   response, apiErr := APICall(chunkedIds)<br>   ch &lt;- result{response, apiErr}<br>  }()<br> }<br><br> log.Println(&quot;Waiting for results...&quot;)<br> results := make([]string, len(ids))<br> var err error<br> for i := 0; i &lt; len(ids); i++ {<br>  rs := &lt;-ch<br>  if rs.err != nil {<br>   err = rs.err<br>   break<br>  }<br>  results[i] = rs.response<br> }<br><br> return results, err<br>}</pre><p>The code blocks in this example will be repeated wherever this requirement is needed. To avoid duplication and improve readability, we have created a struct called Future that performs these operations. Here is how we have implemented the code using the Future struct:</p><pre>func ChunkRequestAndGetAll(ids []string) ([]string, error) {<br> var chunkOfIds [][]string = chunk(ids, chunkSize)<br> <br>futures := make([]*future.Future[string], len(chunkOfIds))<br> for i := range chunkOfIds {<br>  chunkedIds := chunkOfIds[i]<br>  futures[i] = future.Run(func() (string, error) {<br>   return APICall(chunkedIds)<br>  })<br> }<br><br> log.Println(&quot;Waiting for result...&quot;)<br> results, err := future.GetAll(futures)<br> return results, err<br>}</pre><p><strong>Independent Services</strong></p><p>The code block below demonstrates how to send a parallel request to two different services</p><pre>/***--- With directly use channel and goroutine ---***/<br>func DirectlyUse() error {<br> ch1 := make(chan result[string])<br> go func() {<br>  response, err := APICall(&quot;call&quot;)<br>  ch1 &lt;- result[string]{response, err}<br> }()<br><br> ch2 := make(chan result[int64])<br> go func() {<br>  response, err := AnotherAPICall()<br>  ch2 &lt;- result[int64]{response, err}<br> }()<br><br> res1 := &lt;-ch1<br> if res1.err == nil {<br>  return res1.err<br> }<br> res2 := &lt;-ch2<br> if res2.err != nil {<br>  return res2.err<br> }<br> //somethings<br>}</pre><p>Here is how we have implemented the code using the Future struct to simplify error handling and channel usage.</p><pre>/***--- With future struct ---***/<br>func WithFutureStruct() error {<br> fut1 := future.Run(func() (string, error) {<br>  return APICall(&quot;call&quot;)<br> })<br><br> fut2 := future.Run(func() (int64, error) {<br>  return AnotherAPICall()<br> })<br><br> res1, err1 := fut1.Get()<br> res2, err2 := fut2.Get()<br><br> if err1 == nil {<br>  return err1<br> }<br><br> if err2 != nil {<br>  return err2<br> }<br> //somethings<br>}</pre><p>And we can also do it like this. Unlike the example above, this one waits for fut1 and fut2 simultaneously. If an error is encountered in one of them, the other future is not waited for, and the function returns an error.</p><pre><br>/***--- Alternative future struct ---***/<br>func WithFutureStruct() error {<br> fut1 := future.Run(func() (any, error) {<br>  return APICall(&quot;call&quot;)<br> })<br><br> fut2 := future.Run(func() (any, error) {<br>  return AnotherAPICall()<br> })<br><br> err := future.WaitFor(fut1, fut2)<br> if err != nil {<br>  return err<br> }<br> result1 := future.GetResult[string](fut1)<br> result2 := future.GetResult[int64](fut2)<br> //somethings<br>}<br></pre><p>You can use and review the library that I mentioned in this article on GitHub using the following link: [<a href="https://github.com/Trendyol/go-future">github link</a>]</p><p><em>Thanks to </em><a href="https://medium.com/u/df34a29d57e6?source=post_page-----eaf67b44bf15--------------------------------"><em>Emre Odabas</em></a><em> for his support and encouragement in writing this article.</em></p><p>If you’re interested in joining our team, you can apply for <a href="https://jobs.lever.co/trendyol/4bf7e1b0-1e26-4a2f-9208-f156b8437e8c?lever-via=dSAoWKg-1Z">the role of backend developer</a> or any of our current <a href="https://jobs.lever.co/trendyol?lever-via=dSAoWKg-1Z">open positions</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=272a4799df3f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/concurrency-with-goroutines-272a4799df3f">Concurrency with Goroutines</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>