<?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 Ömer Ceylan on Medium]]></title>
        <description><![CDATA[Stories by Ömer Ceylan on Medium]]></description>
        <link>https://medium.com/@ceylanomer?source=rss-b2130bfbed87------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*r1l_hQ5lSaZxTJk_K0ud3A.jpeg</url>
            <title>Stories by Ömer Ceylan on Medium</title>
            <link>https://medium.com/@ceylanomer?source=rss-b2130bfbed87------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 07:35:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ceylanomer/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[Distributed Tracing in Kafka Messages with OpenTelemetry in Golang]]></title>
            <link>https://ceylanomer.medium.com/distributed-tracing-in-kafka-messages-with-opentelemetry-3cb944219fe1?source=rss-b2130bfbed87------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cb944219fe1</guid>
            <category><![CDATA[distributed-tracing]]></category>
            <category><![CDATA[opentelemetry]]></category>
            <category><![CDATA[sarama]]></category>
            <category><![CDATA[observability]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Ömer Ceylan]]></dc:creator>
            <pubDate>Wed, 26 Feb 2025 17:09:33 GMT</pubDate>
            <atom:updated>2025-02-26T17:10:35.392Z</atom:updated>
            <content:encoded><![CDATA[<p>In modern microservice architectures, <strong>tracking events across services communicating via message queues like Kafka </strong>can be challenging. It is crucial to have an effective <strong>distributed tracing mechanism</strong> to monitor where an event originates and where it is consumed.</p><p>Previously, OpenTelemetry support was available in the <strong>Shopify/Sarama</strong> package due to a community contribution. However, after IBM, this built-in support became unavailable. As a result, we need to manually propagate the trace context, ensuring proper distributed tracing in Kafka-based systems.</p><p>In this article, we will learn how to <strong>trace Kafka events end-to-end</strong> using <strong>Sarama and OpenTelemetry</strong>. We will connect <strong>producer and consumer spans</strong> to be visible in <strong>OpenTelemetry-enabled Jaeger UI</strong>.</p><h3>Problem: No Trace Connection in Kafka Events</h3><p>When a microservice <strong>sends an event to Kafka</strong>, the consuming service usually <strong>starts a new trace</strong>, breaking the connection.</p><p><strong>As a result:</strong></p><ul><li>In Jaeger or Grafana, <strong>producer and consumer appear in separate traces</strong>.</li><li>Tracking the event’s journey becomes difficult.</li></ul><p><strong>Solution:</strong> Use OpenTelemetry to carry the full trace context in Kafka headers and extract it in the consumer to properly link spans.</p><h3>Required Dependencies</h3><p>First, install OpenTelemetry and Kafka clients:</p><pre># OpenTelemetry SDK and tools<br>go get go.opentelemetry.io/otel<br>go get go.opentelemetry.io/otel/trace<br>go get go.opentelemetry.io/otel/sdk/trace<br><br>go get github.com/IBM/sarama</pre><h3>Setting Up OpenTelemetry Tracer</h3><p>First, create a file to initialize the <strong>tracer</strong>:</p><pre>package tracer<br><br>import (<br> &quot;context&quot;<br> &quot;golang-sarama-poc/pkg/config&quot;<br><br> &quot;go.opentelemetry.io/otel&quot;<br> &quot;go.opentelemetry.io/otel/exporters/otlp/otlptrace&quot;<br> &quot;go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp&quot;<br> &quot;go.opentelemetry.io/otel/propagation&quot;<br> &quot;go.opentelemetry.io/otel/sdk/resource&quot;<br> &quot;go.opentelemetry.io/otel/sdk/trace&quot;<br> semconv &quot;go.opentelemetry.io/otel/semconv/v1.4.0&quot;<br> &quot;go.uber.org/zap&quot;<br>)<br><br>func InitTracer(jaegerConfig config.JaegerConfig) *trace.TracerProvider {<br><br> headers := map[string]string{<br>  &quot;content-type&quot;: &quot;application/json&quot;,<br> }<br><br> exporter, err := otlptrace.New(<br>  context.Background(),<br>  otlptracehttp.NewClient(<br>   otlptracehttp.WithEndpoint(jaegerConfig.URL),<br>   otlptracehttp.WithHeaders(headers),<br>   otlptracehttp.WithInsecure(),<br>  ),<br> )<br> if err != nil {<br>  zap.L().Fatal(&quot;Failed to create stdout exporter&quot;, zap.Error(err))<br> }<br><br> tp := trace.NewTracerProvider(<br>  trace.WithSampler(trace.AlwaysSample()),<br>  trace.WithBatcher(exporter),<br>  trace.WithResource(<br>   resource.NewWithAttributes(<br>    semconv.SchemaURL,<br>    semconv.ServiceNameKey.String(&quot;golang-sarama-poc&quot;),<br>   )),<br> )<br><br> otel.SetTracerProvider(tp)<br> otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))<br> return tp<br>}</pre><p><strong>What did we do?</strong></p><ul><li>Created an OpenTelemetry <strong>Tracer Provider</strong>.</li><li>This can be used across all services.</li></ul><h3>Kafka Producer: Sending Events with Trace Context</h3><p>The producer injects the full OpenTelemetry trace context into the Kafka message headers. Instead of carrying only the trace_id, the entire trace context — including trace_id, span_id, and other propagation metadata — is added. This ensures that when the consumer processes the message, it can correctly link the new span to the existing trace.</p><pre><br>func (p *KafkaProducer) SendMessage(topic string, key string, value []byte) error {<br><br> tracer := otel.Tracer(&quot;kafka-producer&quot;)<br><br> ctx, span := tracer.Start(context.Background(), &quot;produceMessage&quot;)<br> defer span.End()<br><br> propagator := otel.GetTextMapPropagator()<br> carrier := propagation.MapCarrier{}<br> propagator.Inject(ctx, carrier)<br><br> var headers []sarama.RecordHeader<br> for k, v := range carrier {<br>  headers = append(headers, sarama.RecordHeader{<br>   Key:   []byte(k),<br>   Value: []byte(v),<br>  })<br> }<br><br> msg := &amp;sarama.ProducerMessage{<br>  Topic:   topic,<br>  Value:   sarama.ByteEncoder(value),<br>  Headers: headers,<br> }<br><br> if key != &quot;&quot; {<br>  msg.Key = sarama.StringEncoder(key)<br> }<br><br> partition, offset, err := p.producer.SendMessage(msg)<br> if err != nil {<br>  span.RecordError(err)<br>  zap.L().Error(&quot;Failed to send message&quot;,<br>   zap.String(&quot;topic&quot;, topic),<br>   zap.Error(err))<br>  return err<br> }<br><br> zap.L().Debug(&quot;Message sent successfully&quot;,<br>  zap.String(&quot;topic&quot;, topic),<br>  zap.Int32(&quot;partition&quot;, partition),<br>  zap.Int64(&quot;offset&quot;, offset))<br><br> return nil<br>}</pre><p><strong>What did we do?</strong></p><ul><li>Created a new span with OpenTelemetry.</li><li><strong>Added the trace context to the Kafka message headers</strong>.</li><li>The event <strong>carries the full trace context </strong>when sent.</li></ul><h3>Kafka Consumer: Reading Trace Context from Headers and Linking Spans</h3><p>The consumer <strong>reads the trace context from Kafka headers</strong> and links the new span.</p><pre><br>func Topic1Handler(message *sarama.ConsumerMessage) error {<br> <br> tracer := otel.Tracer(&quot;kafka-consumer&quot;)<br> carrier := propagation.MapCarrier{}<br> for _, h := range message.Headers {<br>  carrier[string(h.Key)] = string(h.Value)<br> }<br><br> propagator := otel.GetTextMapPropagator()<br> ctx := propagator.Extract(context.Background(), carrier)<br><br> ctx, span := tracer.Start(ctx, &quot;consumeMessage&quot;)<br> span.SetAttributes(attribute.String(&quot;kafka.topic&quot;, message.Topic))<br> defer span.End()<br><br> var product models.ProductEvent<br> if err := json.Unmarshal(message.Value, &amp;product); err != nil {<br>  zap.L().Error(&quot;Failed to unmarshal product update event&quot;,<br>   zap.Error(err),<br>   zap.ByteString(&quot;message&quot;, message.Value))<br>  return err<br> }<br><br> zap.L().Info(&quot;Product update event received&quot;,<br>  zap.String(&quot;id&quot;, product.ID),<br>  zap.String(&quot;name&quot;, product.Name),<br>  zap.String(&quot;topic&quot;, message.Topic),<br>  zap.Int32(&quot;partition&quot;, message.Partition),<br>  zap.Int64(&quot;offset&quot;, message.Offset))<br><br> return nil<br>}</pre><p><strong>What did we do?</strong></p><ul><li><strong>Extracted trace context from Kafka headers.</strong></li><li>Created a new span <strong>linked to this context</strong>.</li><li>In OpenTelemetry UI, <strong>producer and consumer now appear under the same trace</strong>!</li></ul><h3>Result: Viewing Event Flow in Tracing UI</h3><p>After running the application, you should see the following in <strong>Jaeger UI</strong>:</p><ul><li><strong>Producer and Consumer should be under the same trace!</strong></li><li><strong>The event flow should be fully visible!</strong></li></ul><pre># Open Jaeger UI<br>http://localhost:16686</pre><p><strong>You can now trace your Kafka events end-to-end!</strong></p><h3>Conclusion and Key Takeaways</h3><ul><li><strong>Trace Context is now carried in Kafka messages.</strong></li><li><strong>Producer and Consumer spans are linked.</strong></li><li><strong>Distributed tracing with OpenTelemetry is enabled.</strong></li><li><strong>The event flow is visible in Jaeger UI.</strong></li></ul><p><strong>Using this approach, you can significantly improve observability in your microservices architecture.</strong></p><p><a href="https://github.com/ceylanomer/golang-sarama-poc">Repository Link</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cb944219fe1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arrays And Slices in Golang]]></title>
            <link>https://ceylanomer.medium.com/arrays-and-slices-in-golang-3d535eff300d?source=rss-b2130bfbed87------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d535eff300d</guid>
            <category><![CDATA[lists]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[go-slices]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Ömer Ceylan]]></dc:creator>
            <pubDate>Tue, 17 Oct 2023 22:07:18 GMT</pubDate>
            <atom:updated>2023-10-17T22:14:13.824Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*xEW0KCu_8FF38JjQ.png" /></figure><p>In Go (or Golang), arrays and slices are fundamental data structures for managing collections of data. While they share some similarities, they have important differences in terms of size and flexibility.</p><h3>Arrays</h3><ul><li>An array in Go is a fixed-size data structure that stores elements of the same type.</li><li>You need to specify the size of the array when you declare it.</li><li>Once an array is defined, its size cannot be changed.</li><li>Arrays are often used when you know the exact number of elements you need in advance.</li></ul><p>Here is an examples of declaring and initializing an array in Go:</p><pre>var numbers [5]int // An integer array with a fixed size of 5<br>numbers = [5]int{1, 2, 3, 4, 5}</pre><pre>numbers := [...]int{1, 2, 3, 4, 5} // Size calculated automatically</pre><p>Just like in other languages, you can perform various manipulations on arrays, although they might not be as extensive as slices.</p><h4>Iteration</h4><p>If the feature under development requires iteration over an array, it can be implemented as follows.</p><pre>arr := [5]int{1, 2, 3, 4, 5}<br>for i := 0; i &lt; len(arr); i++ {<br>    fmt.Println(arr[i])<br>}</pre><h4>Adding Items</h4><p>Arrays have a fixed size, so you cannot dynamically add or remove elements from them. If your feature development requires operations like adding or removing elements, using slices would be much more appropriate.</p><h4>Updating Items</h4><p>You can update items in an array by reassigning a new value to a specific index:</p><pre>arr := [5]int{1, 2, 3, 4, 5}<br>arr[2] = 10</pre><h4>Deleting Items</h4><p>Like adding items, you cannot directly delete items from an array. You may need to create a new array without the item you want to remove.</p><h4>Searching</h4><p>If you need to perform a search on arrays, you can use the standard library shown below.</p><pre>target := 3<br>found := false<br>for _, value := range arr {<br>    if value == target {<br>        found = true<br>        break<br>    }<br>}</pre><h4>Sorting</h4><p>You can sort an array using the sort package in the standard library:</p><pre>import &quot;sort&quot;<br>arr := []int{5, 3, 1, 4, 2}<br>sort.Ints(arr)</pre><h4>Filtering</h4><p>You can filter elements from an array based on a condition by creating a new slice and appending the elements that meet the condition:</p><pre>original := []int{1, 2, 3, 4, 5}<br>filtered := []int{}<br>for _, value := range original {<br>    if value &gt; 2 {<br>        filtered = append(filtered, value)<br>    }<br>}</pre><h4>Reversing</h4><p>You can reverse the order of elements in an array by swapping elements:</p><pre>arr := []int{1, 2, 3, 4, 5}<br>for i, j := 0, len(arr)-1; i &lt; j; i, j = i+1, j-1 {<br>    arr[i], arr[j] = arr[j], arr[i]<br>}</pre><h4>Concatenating</h4><p>You can concatenate two or more arrays or slices by creating a new slice and appending the elements from the original arrays/slices.</p><p>Remember that arrays in Go have a fixed size, and if you need dynamic resizing and more manipulation capabilities, consider using slices, which are more flexible for managing collections of data.</p><h3>Slices</h3><ul><li>A slice, on the other hand, is a dynamically-sized, flexible view into the elements of an underlying array.</li><li>Slices are created using the make() function or by slicing an existing array, another slice, or a string.</li><li>Slices can grow or shrink as needed.</li><li>Slices are more commonly used in Go because they provide greater flexibility when working with collections of data.</li></ul><p>Here is an example of declaring and initializing a slice in Go:</p><pre>var numbers []int // A slice with no fixed size, initially nil<br>numbers = []int{1, 2, 3, 4, 5} // Initialize the slice</pre><p>You can also create a slice by slicing an array:</p><pre>arr := [5]int{1, 2, 3, 4, 5}<br>slice := arr[1:4] // This creates a slice containing elements at indices 1, 2, and 3 of the array</pre><h4>Appending Items</h4><p>You can add items to a slice using the append function. It dynamically resizes the slice to accommodate the new items:</p><pre>slice := []int{1, 2, 3}<br>slice = append(slice, 4, 5)</pre><h4>Updating Items</h4><p>To update an item in a slice, simply assign a new value to the slice at the desired index:</p><pre>slice := []int{1, 2, 3, 4, 5}<br>slice[2] = 10</pre><h4>Deleting Items</h4><p>You can delete an item from a slice by creating a new slice without the item you want to remove:</p><pre>slice := []int{1, 2, 3, 4, 5}<br>indexToDelete := 2<br>slice = append(slice[:indexToDelete], slice[indexToDelete+1:]...)</pre><h4>Slicing a Slice</h4><p>You can create a new slice by slicing an existing slice, specifying the start and end indices. This operation extracts a subset of the original slice:</p><pre>originalSlice := []int{1, 2, 3, 4, 5}<br>newSlice := originalSlice[1:4] // [2, 3, 4]</pre><h4>Copying Slices</h4><p>You can create a copy of a slice using the copy function</p><pre>sourceSlice := []int{1, 2, 3}<br>targetSlice := make([]int, len(sourceSlice))<br>copy(targetSlice, sourceSlice)</pre><h4>Sorting a Slice</h4><p>You can sort a slice using the sort package in the standard library:</p><pre>import &quot;sort&quot;<br>slice := []int{5, 3, 1, 4, 2}<br>sort.Ints(slice)</pre><h4>Filtering Items</h4><p>You can create a new slice that contains only items meeting a specific condition:</p><pre>originalSlice := []int{1, 2, 3, 4, 5}<br>filteredSlice := []int{}<br>for _, value := range originalSlice {<br>    if value &gt; 2 {<br>        filteredSlice = append(filteredSlice, value)<br>    }<br>}</pre><h4>Reversing a Slice</h4><p>You can reverse the order of elements in a slice by swapping elements:</p><pre>slice := []int{1, 2, 3, 4, 5}<br>for i, j := 0, len(slice)-1; i &lt; j; i, j = i+1, j-1 {<br>    slice[i], slice[j] = slice[j], slice[i]<br>}</pre><p>If your project involves frequent use of operations like searching, filtering, sorting, and complex business logic development, the <a href="https://github.com/ahmetb/go-linq">Linq</a> package is a widely used package for such tasks. You can find detailed documentation in the repository.</p><p>In summary, arrays have a fixed size, while slices are dynamically-sized and provide more flexibility. Slices are used more frequently in Go for managing collections of data due to their versatility.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d535eff300d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Variables in Golang]]></title>
            <link>https://ceylanomer.medium.com/variables-in-golang-7b4753af945a?source=rss-b2130bfbed87------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b4753af945a</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[variable-shadowing]]></category>
            <category><![CDATA[primitive-data-types]]></category>
            <category><![CDATA[variable-in-golang]]></category>
            <category><![CDATA[type-conversion]]></category>
            <dc:creator><![CDATA[Ömer Ceylan]]></dc:creator>
            <pubDate>Thu, 12 Oct 2023 16:05:32 GMT</pubDate>
            <atom:updated>2023-10-12T16:05:32.034Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EIUPPAZAouCn5uG3" /><figcaption>variables_in_golang</figcaption></figure><p>I believe that starting the article series with variables, as is the case in every language, would be the right approach. I tried to list some essential topics that should be covered about variables, as follows;</p><ul><li>Variable Declaration</li><li>Visibility</li><li>Naming Conventions</li><li>Redeclaration and shadowing</li><li>Type Conversions</li></ul><h3>Variable Declaration</h3><p>I believe it would be beneficial to start by sharing a list of basic variable types in Go.</p><ol><li><strong>int</strong>: Represents integers. Default value is 0.</li><li><strong>float64</strong>: Represents floating-point numbers (64-bit precision). Default value is 0.0.</li><li><strong>string</strong>: Represents text or character strings. Default value is an empty string, “”.</li><li><strong>bool</strong>: Represents boolean values (true or false). Default value is false.</li><li><strong>byte</strong>: Represents 8-bit unsigned integers (equivalent to uint8). Default value is 0.</li><li><strong>rune</strong>: Represents Unicode characters (equivalent to int32). Default value is 0.</li><li><strong>int8</strong>, <strong>int16</strong>, <strong>int32</strong>, <strong>int64</strong>: Represents integers with different bit lengths. Default value is 0.</li><li><strong>uint8</strong>, <strong>uint16</strong>, <strong>uint32</strong>, <strong>uint64</strong>: Represents unsigned integers with different bit lengths. Default value is 0.</li><li><strong>uintptr</strong>: Represents an unsigned integer type and is used for holding pointers. Default value is 0.</li></ol><p>Please note that the default values are initialized when variables are declared but not explicitly initialized. Default variable types in Go are not reference types, so they are not nullable. Therefore, variables have zero values, which vary depending on the variable type, as you may know. In Go, for all numeric types, the default value is <strong>0</strong>, for boolean it’s <strong>false</strong>, and for strings, it’s an empty string (<strong>“”</strong>).</p><p>If you only want to create a variable within a function, you can do it as follows.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br> var i int<br> fmt.Println(i)<br>}<br><br>//Console Output<br>// 0</pre><p>In Golang, you can create and declare variables in various ways.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br> var i int<br> fmt.Println(i)<br><br> i = 23<br> fmt.Println(i)<br><br> var t int = 25<br> fmt.Println(t)<br><br> t1 := 27<br> fmt.Println(t1)<br><br>}<br><br>//Console Output<br>// 0<br>// 23<br>// 25<br>// 27</pre><p>You can also declare variables at the package level in Golang, but these declarations should be in the full declaration form; you cannot use short variable declarations at the package level. You can declare variables individually, or you can declare them in blocks.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>var t int = 45<br><br>var (<br> t1         int = 35<br> t2         int = 35<br> t3, t4, t6     = 23, 33, 43<br>)<br><br>func main() {<br> fmt.Println(t)<br> fmt.Println(t6)<br><br>}<br><br>//Console Output<br>//45<br>//43</pre><h3>Visibility And Naming Conventions</h3><p>I wanted to explain Visibility and Naming Conventions together because they are somewhat interconnected topics. For instance, when you create a variable at the package level, using uppercase in its naming signifies that this variable can also be used from outside the package. This implies that when naming a variable, you should consider its scope. If you define a variable in lowercase, it will be accessible and visible from within the package it’s defined in. This rule set also applies to function names, although that could be a topic for another article.</p><p>In addition to this, there are a few more important points to mention. In variable naming, camelCase is generally used. When naming variables, especially at the function scope, shorter names can be more practical. However, if you’re defining private (lowercase) or package-level global (uppercase) variables, the name you give to the variable should be meaningful, considering that others might also use your variable. Not following this practice can lead to chaos in projects over time.</p><h3>Redeclaration and Shadowing</h3><p>In Golang, a variable you define is valid within the scope in which it is defined. This means that if you have a variable defined at the package level and you define another variable with the same name at the function level, the function-level variable will take precedence.</p><p>Additionally, if a variable is defined within a function with the same name as a package-level variable, assigning a value to it will not affect the value of the package-level variable. But you can modify the value of a package-level variable by assigning a new value to it from another function.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>var t int = 45<br><br>func main() {<br> fmt.Println(t)<br><br> shadowing1()<br> shadowing2()<br> shadowing3()<br> shadowing4()<br>}<br><br>func shadowing1() {<br> t := 24<br> fmt.Println(t)<br>}<br><br>func shadowing2() {<br> fmt.Println(t)<br>}<br><br>func shadowing3() {<br> t = 27<br> fmt.Println(t)<br>}<br><br>func shadowing4() {<br> fmt.Println(t)<br>}<br><br>//Console Output<br>//45<br>//24<br>//45<br>//27<br>//27</pre><h3>Type Conversions</h3><p>There are various methods to convert data types in Golang. For example, you can convert an integer variable to a float type as shown below:</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br>    integerVariable := 33<br>    floatVariable := float64(integerVariable)<br><br>    fmt.Printf(&quot;integerVariable: %d\n&quot;, integerVariable)<br>    fmt.Printf(&quot;floatVariable: %f\n&quot;, floatVariable)<br>}<br><br>//Console Output<br>//integerVariable: 33<br>//floatVariable: 33.000000</pre><p>In the above example, we converted an integer variable named integerVariable to a float64 type variable named floatVariable. To perform the conversion, we specified the target type within parentheses. With this method, we converted an integer to a floating-point number and printed the results to the screen.</p><p>Additionally, in Golang, conversion operations can be performed using both type assertions and custom functions. Here are some examples:</p><pre>var x interface{} = 42<br>i, ok := x.(int)<br>if ok {<br>    fmt.Println(&quot;x has been converted to int:&quot;, i)<br>} else {<br>    fmt.Println(&quot;Conversion failed.&quot;)<br>}</pre><pre>type Celsius float64<br>type Fahrenheit float64<br><br>func CToF(c Celsius) Fahrenheit {<br>    return Fahrenheit(c*9/5 + 32)<br>}<br><br>celsiusValue := Celsius(100.0)<br>fahrenheitValue := CToF(celsiusValue)<br>fmt.Printf(&quot;%.2f°C has been converted to %.2f°F\n&quot;, celsiusValue, fahrenheitValue)</pre><p>It’s important to remember that when converting large types to smaller types, data loss can occur if the values are sufficiently large. Data loss can be a concern, especially when converting decimal numbers to integers or large integers to small integers. Conversion operations should be carefully planned and tailored to your specific needs.</p><p>Hoping to continue publishing these little articles whenever I have time.</p><p>I hope you enjoyed reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b4753af945a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[.Net Core’da Entity Framework Core ile CRUD İşlemleri Serisi — 2]]></title>
            <link>https://medium.com/multinetinventiv/net-coreda-entity-framework-core-ile-crud-i%CC%87%C5%9Flemleri-serisi-2-1678b0ce0b4f?source=rss-b2130bfbed87------2</link>
            <guid isPermaLink="false">https://medium.com/p/1678b0ce0b4f</guid>
            <category><![CDATA[entity-framework]]></category>
            <category><![CDATA[entity-framework-core]]></category>
            <category><![CDATA[ef-core]]></category>
            <category><![CDATA[türkçe]]></category>
            <category><![CDATA[net-core]]></category>
            <dc:creator><![CDATA[Ömer Ceylan]]></dc:creator>
            <pubDate>Tue, 02 Jul 2019 05:33:46 GMT</pubDate>
            <atom:updated>2019-07-02T05:33:46.168Z</atom:updated>
            <content:encoded><![CDATA[<h3>.Net Core’da Entity Framework Core ile CRUD İşlemleri Serisi — 2</h3><p>.Net Core’da Entity Framework Core ile CRUD İşlemleri Serisi ikinci yazımızda EF Core ile Select, Update ve Delete işlemlerini genel olarak anlatacağız. Serinin ilk yazısına ulaşmak için aşağıdaki linki takip edebilirsiniz;</p><p><a href="https://medium.com/multinetinventiv/net-coreda-entity-framework-core-ile-crud-i%CC%87%C5%9Flemleri-serisi-1-fa451d295889">.Net Core’da Entity Framework Core ile CRUD İşlemleri Serisi — 1</a></p><p>Önceki yazımızda entity olarak Issuer sınıfımızı ve veritabanı modelimizi oluşturup sonrasında Entity Framework Core ile Insert işlemi gerçekleştirmiştik. Bu yazımızda ise veritabanında bulunan veri üzerinde belirli parametrelerle Select, Update ve Delete işlemi yapacağız.</p><p><strong>EF Core ile Select İşlemi Gerçekleştirme</strong></p><p>Veri tabanımızda bulunan veri içinden sınıfımız için belirlediğimiz alanları kullanarak Select işlemi gerçekleştirebiliriz. Select işlemini gerçekleştirirken primary key olarak belirlediğimiz Id alanını kullanarak belirli bir kaydı ya da Status gibi bir alanı kullanarak aynı özelliğe sahip birden fazla kaydı çekebiliriz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*8UNC7t4iDOWlyrlY66glLQ.png" /></figure><p>Bu örnekte GetIssuer methoduna verilen integer tipindeki id parametresi ile veri tabanımızdan aynı id’ye sahip Issuer objesini çekiyoruz. İşlem bir Select işlemi olduğu için Insert işlemindeki gibi SaveChanges() methodunu kullanmaya ihtiyacımız yoktur.</p><p>Ayrıca veritabanımızda bulunan veri içinden Status alanı true ya da false olan Issuer objelerini çekmek istediğimizde aşağıdaki gibi bir kod bloğu kullanabiliriz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*-DlGSBBB0tyWI23u0qpBeg.png" /></figure><p>GetIssuerByStatus methoduna verilen boolean tipindeki parametreye göre select işlemini yukarıdaki gibi gerçekleştirebiliriz. Where methoduna parametre olarak verdiğimiz Lambda ile SQL’de yapılabilen neredeyse tüm sorguları gerçekleştirebiliriz. Aynı anda birden fazla parametreyi, eğer sınıflarımız arasında one-to-one, many-to-one gibi ilişkiler varsa ilişkide olduğu diğer entitylerin property’lerini kullanarak da select işlemini gerçekleştirebiliriz. Ayrıca aşağıdaki linkten LINQ ve Lambda ile ilgili yapabileceğiniz çeşitli sorgu tiplerini de inceleyebilirsiniz.</p><p><a href="https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b">101 LINQ Samples in C#</a></p><p><strong>EF Core ile Update İşlemi Gerçekleştirme</strong></p><p>Yazımızın bu bölümünde EF Core ile Update işlemi gerçekleştirme üzerinde duracağız. EF Core kullanarak veritabanımızda bulunan bir kaydı aşağıdaki şekilde güncelleyebiliriz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*G8HEm4dsgRnl2-8x7WXwtw.png" /></figure><p>Update işleminde de daha önce Insert işleminde kullandığımız gibi SaveChanges methodunu kullanmamız gerekiyor. Fakat güncelleme işlemi için kullandığımız kod parçasını üstünde çalışmakta olduğunuz projenin iş süreçlerine göre tekrar dizayn edebilirsiniz. Bir diğer kullanımı da aşağıdaki gibidir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*eZEWvibw2g-sW2U1AOrebw.png" /></figure><p>EntityState özelliğinden de faydalanarak aşağıdaki gibi de Update işleminizi gerçekleştirebilirsiniz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*G0uiGPUPsmMFAqJOFbzLwA.png" /></figure><p><strong>EF Core ile Delete İşlemi Gerçekleştirme</strong></p><p>Serimizin ikinci yazısı olan bu yazımızın son bölümünde EF Core ile Delete işlemini örneklerle gerçekleştireceğiz. Veritabanımızda bulunan bir kaydı silmek için context’in Remove methodunu kullanabiliriz ayrıca birden fazla kaydı silmek için context’in RemoveRange methodunu da kullanabiliriz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*68LAgkTMnr-XlkwEyFbExw.png" /></figure><p>Update işleminde gerçekleştirdiğimiz gibi delete işleminde de EntityState özelliğini kullanarak delete işlemini gerçekleştirebiliriz. EntityState özellikle concurrency oluşan durumlarda oldukça faydalı olabilmektedir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*iBAMb6YiwPVhGR9jnIg0zg.png" /></figure><p>Ayrıca Insert ve Update işlemini gerçekleştirirken kullandığımız context’e gelen SaveChanges methodunu delete işlemi sonunda da kullanmalıyız. Çünkü veritabanındaki değişiklik SaveChanges methodunu çağırdıktan sonra gerçekleşir.</p><p>.Net Core’da Entity Framework Core ile CRUD işlemleri serimizin bu bölümünde EF Core ile Select, Update ve Delete işlemlerini, implementasyonları ile birlikte temel seviyede anlatmış olduk. Daha detaylı örnekler için aşağıdaki linkten Microsoft dökümanlarını da inceleyebilirsiniz.</p><p><a href="https://docs.microsoft.com/en-us/ef/core/">Overview of Entity Framework Core - EF Core</a></p><p>Serimizin bu bölümünü takip ettiğiniz için teşekkür ederiz.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1678b0ce0b4f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/multinetinventiv/net-coreda-entity-framework-core-ile-crud-i%CC%87%C5%9Flemleri-serisi-2-1678b0ce0b4f">.Net Core’da Entity Framework Core ile CRUD İşlemleri Serisi — 2</a> was originally published in <a href="https://medium.com/multinetinventiv">inventiv</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>