<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Maicon Gavino</title>
    <description>The latest articles on DEV Community by Maicon Gavino (@maicon_gavino).</description>
    <link>https://dev.to/maicon_gavino</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2276258%2Fd28928ea-5a9c-4018-b94e-59b8b68dc26f.jpg</url>
      <title>DEV Community: Maicon Gavino</title>
      <link>https://dev.to/maicon_gavino</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/maicon_gavino"/>
    <language>en</language>
    <item>
      <title>Exploring Unicode with Go and Vue.js</title>
      <dc:creator>Maicon Gavino</dc:creator>
      <pubDate>Fri, 17 Jan 2025 12:20:20 +0000</pubDate>
      <link>https://dev.to/maicon_gavino/exploring-unicode-with-go-and-vuejs-408j</link>
      <guid>https://dev.to/maicon_gavino/exploring-unicode-with-go-and-vuejs-408j</guid>
      <description>&lt;p&gt;Unicode is a fundamental standard in modern computing, ensuring consistent representation and manipulation of text in any language, style, or even emojis. In this article, we’ll explore the Unicode standard to develop a project that converts text into bold, italic, bold/italic, and underlined styles using Golang and Vue.js, providing a practical and efficient approach to text manipulation with Unicode.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkhbk2h928n34ykj68xci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkhbk2h928n34ykj68xci.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project Structure&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Backend in Golang&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Processes requests sent from the frontend, applying transformations to the text based on Unicode table offsets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Frontend in Vue.js&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provides a simple interface where users can input text, send it to the backend, and view the styled results.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;File Structure&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TextConvert/

├── main.go          # Código do servidor em Golang
├── go.mod           # Gerenciador de dependências do Go
└── template/
    ├── index.html   # Interface do usuário
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Backend Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;On the backend, we use Golang to implement a REST API that processes text. The core is the &lt;code&gt;stringFormat&lt;/code&gt; function, which takes the input text as a string along with two integer offsets representing the Unicode shifts for uppercase and lowercase letters. The function iterates through each character in the text, applies the appropriate shifts to style alphabetic characters, and leaves other characters unchanged.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func stringFormat(input string, upperOffset, lowerOffset int) string {
 var result strings.Builder
 for _, r := range input {
  if r &amp;gt;= 'A' &amp;amp;&amp;amp; r &amp;lt;= 'Z' {
   result.WriteRune(rune(int(r) - 'A' + upperOffset))
  } else if r &amp;gt;= 'a' &amp;amp;&amp;amp; r &amp;lt;= 'z' {
   result.WriteRune(rune(int(r) - 'a' + lowerOffset))
  } else {
   result.WriteRune(r)
  }
 }
 return result.String()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function uses Unicode table offsets to transform alphabetic characters into their stylized equivalents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CORS Configuration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To allow the frontend to send requests to the backend, we configure the CORS middleware on the Go server using the &lt;code&gt;enableCORS&lt;/code&gt; function. This configuration is crucial in web applications, where the frontend and backend often operate on different domains.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func enableCORS(next http.Handler) http.Handler {
 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  w.Header().Set("Access-Control-Allow-Origin", "*") // Permite todas as origens
  w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
  w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
  if r.Method == http.MethodOptions {
   w.WriteHeader(http.StatusOK)
   return
  }
  next.ServeHTTP(w, r)
 })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures that the browser does not block requests due to security policies (CORS).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Frontend with Vue.js&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The frontend is implemented in a single &lt;code&gt;index.html&lt;/code&gt; file, leveraging Vue.js for reactivity. It allows the user to input text, send it to the API, and view the styled results. Here’s an example of the Vue component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;!-- Resultado em Negrito --&amp;gt;
            &amp;lt;div class="mb-4 border rounded-lg p-4"&amp;gt;
                &amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;Negrito:&amp;lt;/strong&amp;gt; &amp;lt;span&amp;gt;{{ results.bold }}&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
                &amp;lt;button @click="copyText(results.bold)" class="bg-blue-500 text-white py-1 px-4 rounded mt-2"&amp;gt;
                    Copiar
                &amp;lt;/button&amp;gt;
            &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the Vue.js method for making the request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
    const response = await fetch("https://convert-1tqr.onrender.com/convert", {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
        },
        body: JSON.stringify({ text: this.inputText }),
    });

    if (!response.ok) {
        throw new Error("Erro ao processar o texto.");
    }

    this.results = await response.json();
} catch (error) {
    console.error("Erro:", error);
    alert("Erro ao converter texto. Tente novamente.");
} finally {
    this.isLoading = false;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This project demonstrates how to manipulate text with Unicode using &lt;code&gt;Golang&lt;/code&gt; and &lt;code&gt;Vue.js&lt;/code&gt;, create &lt;code&gt;REST APIs&lt;/code&gt;, and configure integrations following best practices, such as implementing CORS.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Access the complete project via the links below:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Live Demo: &lt;a href="https://magenta-selkie-0df725.netlify.app" rel="noopener noreferrer"&gt;Click here to test&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GitHub Repository: &lt;a href="//github.com/MaiconGavino/TextConvert"&gt;MaiconGavino/TextConvert&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you enjoyed this article, feel free to share it or leave your feedback in the comments.&lt;/p&gt;

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