<?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: Marcos Fonseca</title>
    <description>The latest articles on DEV Community by Marcos Fonseca (@mffonseca).</description>
    <link>https://dev.to/mffonseca</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%2F1119805%2Fe5517946-1ea1-4851-bc66-ba43b801e508.jpg</url>
      <title>DEV Community: Marcos Fonseca</title>
      <link>https://dev.to/mffonseca</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mffonseca"/>
    <language>en</language>
    <item>
      <title>Nem todo dev quer ser CTO, e tudo bem!</title>
      <dc:creator>Marcos Fonseca</dc:creator>
      <pubDate>Tue, 21 Nov 2023 09:53:13 +0000</pubDate>
      <link>https://dev.to/mffonseca/nem-todo-dev-quer-ser-cto-e-tudo-bem-5fl7</link>
      <guid>https://dev.to/mffonseca/nem-todo-dev-quer-ser-cto-e-tudo-bem-5fl7</guid>
      <description>&lt;p&gt;Eu sei, isso pode parecer estranho vindo de alguém envolvido no mundo tech, mas se você, como desenvolvedor(a), está pensando em se tornar sócio(a) de uma startup e assumir o papel de diretor(a) técnico(a), por favor, leia até o final.&lt;/p&gt;

&lt;p&gt;Entenda que ser CTO vai muito além de habilidades técnicas. Demanda anos de experiência em tecnologia e, crucialmente, em gestão e liderança. Você precisará tomar decisões difíceis quase que diariamente, o tempo todo, desde contratações até mesmo a difícil tarefa de demitir pessoas.&lt;/p&gt;

&lt;p&gt;A diferença entre ser um profissional sênior e um CTO é absurdamente grande. Imagine gerenciar uma operação que funciona 24/7, com a responsabilidade de supervisionar todas as áreas. Mesmo tendo uma ou mais equipes abaixo de você, essas preocupações, principalmente técnicas, serão suas também.&lt;/p&gt;

&lt;p&gt;Além de todas as questões de desenvolvimento e produto, você terá que lidar com questões críticas como:&lt;/p&gt;

&lt;p&gt;🚩 Segurança: Proteger a empresa contra ameaças e garantir a segurança de dados.&lt;/p&gt;

&lt;p&gt;🚩 Performance e Disponibilidade do Sistema: Assegurar que os sistemas estejam sempre funcionando eficientemente.&lt;/p&gt;

&lt;p&gt;🚩 Gestão de Equipe e Cultura: Desenvolver uma cultura que promova inovação e gerenciar as dinâmicas da equipe.&lt;/p&gt;

&lt;p&gt;🚩 Estratégia Tecnológica e Inovação: Definir a direção tecnológica da empresa e incorporar inovações.&lt;/p&gt;

&lt;p&gt;🚩 Alocação de Recursos: Gerenciar recursos de forma eficaz para maximizar o retorno.&lt;/p&gt;

&lt;p&gt;🚩 Compliance e Regulamentações: Assegurar que a empresa esteja em conformidade com leis e regulamentos.&lt;/p&gt;

&lt;p&gt;🚩 Comunicação: Manter uma comunicação clara e eficaz com outros diretores, stakeholders e a equipe.&lt;/p&gt;

&lt;p&gt;Além disso, você precisará focar no desenvolvimento da equipe, abordando aspectos como competências, objetivos individuais, aprendizado contínuo, mentoria, feedback e progressão de carreira, etc.&lt;/p&gt;

&lt;p&gt;É muita coisa. Acha que acabou?&lt;/p&gt;

&lt;p&gt;Entrar em uma startup como sócio também traz seus desafios, como a possibilidade de opressão ao minoritário e abuso de poder. É fundamental ter contratos sólidos e conhecer bem seus futuros sócios.&lt;/p&gt;

&lt;p&gt;Entenda, o objetivo não é desmotivar, mas sim alertar sobre pontos que talvez você não esteja refletindo agora.&lt;/p&gt;

&lt;p&gt;Mas, se você optar por não seguir um caminho de gestão, lembre-se de que há muitos outros caminhos possíveis na área de desenvolvimento de software, desde desenvolvedor júnior até engenheiro fellow, cada um com suas próprias responsabilidades e oportunidades de crescimento.&lt;/p&gt;

&lt;p&gt;Como CTO, você será o ponto central por trás da visão e estratégia tecnológica da empresa, um papel que exige não apenas habilidade, mas uma verdadeira paixão por liderança e inovação, além de muito jogo de cintura para lidar com situações adversas.&lt;/p&gt;

&lt;p&gt;Independentemente do caminho que escolher, esteja preparado(a) para os desafios e recompensas que cada nível traz. Não existe um caminho certo ou errado; existe o que você deseja no momento.&lt;/p&gt;

</description>
      <category>desenvolvimento</category>
      <category>carreira</category>
      <category>software</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>If you're a developer and care about code quality, here are some tips for you</title>
      <dc:creator>Marcos Fonseca</dc:creator>
      <pubDate>Sat, 30 Sep 2023 19:29:37 +0000</pubDate>
      <link>https://dev.to/mffonseca/if-youre-a-developer-and-care-about-code-quality-here-are-some-tips-for-you-3bhh</link>
      <guid>https://dev.to/mffonseca/if-youre-a-developer-and-care-about-code-quality-here-are-some-tips-for-you-3bhh</guid>
      <description>&lt;p&gt;Ever had that nagging feeling when looking at someone else's code, realizing they missed some basic concepts? To sidestep that, when you're coding, make sure you're following these principles:&lt;/p&gt;

&lt;p&gt;💻 &lt;strong&gt;Readable Code&lt;/strong&gt;: Write so that your peers can easily understand. Remember: we often spend more time reading code than writing it. Don't be the one who confuses everyone.&lt;/p&gt;

&lt;p&gt;⏱ &lt;strong&gt;Variable and Function Naming&lt;/strong&gt;: Pick clear and descriptive names. If a variable signifies a duration, "duration" is way clearer than just "d". Steer clear of ambiguity.&lt;/p&gt;

&lt;p&gt;🙅🏾‍♂️ &lt;strong&gt;Small and Focused Functions&lt;/strong&gt;: Keep your functions short with a single purpose. They'll be more comprehensible, easy to test, and reusable.&lt;/p&gt;

&lt;p&gt;Regarding function arguments, less truly is more. Ideally, go without; but when necessary, cap it at three. No one's a fan of convoluted functions, but yes, there are always exceptions.&lt;/p&gt;

&lt;p&gt;Steer clear of functions with unpredictable side effects. A function should deliver exactly what it promises.&lt;/p&gt;

&lt;p&gt;On the topic of classes, adhere to the single responsibility principle. It'll save you headaches down the road.&lt;/p&gt;

&lt;p&gt;Avoid unnecessary comments. Your code should speak for itself. If you're explaining too much in comments, you might need to rethink something.&lt;/p&gt;

&lt;p&gt;Proper error handling is a must. Stay true to best practices and avoid vague returns. Your team will be grateful.&lt;/p&gt;

&lt;p&gt;Leaving behind dead (unused) code? It's akin to a messy room. Keep your coding space neat.&lt;/p&gt;

&lt;p&gt;✅ Uniform formatting is akin to maintaining a professional demeanor, much like adhering to a dress code.&lt;/p&gt;

&lt;p&gt;Never doubt that the caliber of your code mirrors your prowess as a developer. Stand tall, champion quality, and let your professionalism shine through.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building JWT Authentication in Go: A guide with middleware and helper packages</title>
      <dc:creator>Marcos Fonseca</dc:creator>
      <pubDate>Wed, 19 Jul 2023 19:27:12 +0000</pubDate>
      <link>https://dev.to/mffonseca/building-jwt-authentication-in-go-a-guide-with-middleware-and-helper-packages-2idn</link>
      <guid>https://dev.to/mffonseca/building-jwt-authentication-in-go-a-guide-with-middleware-and-helper-packages-2idn</guid>
      <description>&lt;p&gt;In this project, we dive deeply into one of the most critical aspects of any web application: authentication. However, instead of taking the more traditional route, we explore the implementation of JWT authentication in Go, a modern and secure approach to keeping our users authenticated.&lt;/p&gt;

&lt;p&gt;The JSON Web Token (JWT) provides a robust and scalable method for handling user authentication and the secure transmission of information between parties. We use the "github.com/golang-jwt/jwt/v4" package to handle the creation and validation of our tokens.&lt;/p&gt;

&lt;p&gt;A highlight of the project is the use of middleware to handle the authentication of each request. This allowed the authentication logic to be separated from the rest of the code, improving readability and maintenance.&lt;/p&gt;

&lt;p&gt;In addition, we used a variety of helper packages to optimize our application. The Gorilla Mux router, "github.com/gorilla/mux", provides flexible and powerful HTTP request routing. The "github.com/joho/godotenv" package is used for managing environment variables, simplifying the configuration across different development environments.&lt;/p&gt;

&lt;p&gt;We adopted "github.com/sirupsen/logrus" to handle server logs, providing flexibility for logging debug events, errors, and general information.&lt;/p&gt;

&lt;p&gt;This project is an excellent reference for developers looking to understand how to implement JWT authentication in Go, offering a detailed view of how these concepts can be used in practice. Furthermore, it demonstrates the power of middleware in separating responsibilities and creating clean, easy-to-maintain code.&lt;/p&gt;

&lt;h2&gt;
  
  
  JWT Auth Server
&lt;/h2&gt;

&lt;p&gt;This is a simple authentication server in Golang using JWT (JSON Web Tokens) for user authentication. The project is made up of different routes and handlers for signing in, welcoming, refreshing token, and logging out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Methods
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;main()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the entry point for the server. It sets up the log format, loads environment variables from the .env file, initializes a router, sets up routes, and starts the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Welcome(w http.ResponseWriter, r *http.Request)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This handler is responsible for welcoming the user. It fetches a token from the cookie, verifies the token's validity, extracts the claims, and returns a welcome message to the user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Signin(w http.ResponseWriter, r *http.Request)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This handler is responsible for logging the user in. It reads credentials from the request body, validates these credentials, creates a JWT token, and returns it in a cookie.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Refresh(w http.ResponseWriter, r *http.Request)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This handler is responsible for refreshing the user's JWT token. It fetches the token from the cookie, verifies its validity, creates a new token, and returns it in a cookie.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Logout(w http.ResponseWriter, r *http.Request)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This handler is responsible for logging the user out. It simply removes the cookie, effectively invalidating the user's JWT token.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AuthenticationMiddleware(next http.Handler) http.Handler&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This middleware is responsible for verifying the user's authentication. It's used on routes that require authentication.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation Instructions
&lt;/h2&gt;

&lt;p&gt;First, clone the repository with git clone.&lt;/p&gt;

&lt;p&gt;Then, at the root of the project, create a &lt;strong&gt;.env&lt;/strong&gt; file with the secret key for the JWT like so: JWT_KEY=yoursecretkey.&lt;/p&gt;

&lt;p&gt;Run the command go build to compile the code.&lt;/p&gt;

&lt;p&gt;Finally, run the command &lt;strong&gt;./yourfilename&lt;/strong&gt; to start the server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing Instructions
&lt;/h2&gt;

&lt;p&gt;Use a tool like Postman or cURL to make a POST request to localhost:8080/signin with a JSON body containing username and password. You should receive a cookie with a JWT token.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "username": "admin",
    "password": "123456"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make a GET request to &lt;strong&gt;localhost:8080/welcome&lt;/strong&gt; with the JWT token you received. You should receive a welcome message with the username.&lt;/p&gt;

&lt;p&gt;Make a POST request to &lt;strong&gt;localhost:8080/refresh&lt;/strong&gt; with the JWT token to receive a new token.&lt;/p&gt;

&lt;p&gt;Make a GET request to &lt;strong&gt;localhost:8080/logout&lt;/strong&gt; to invalidate the token.&lt;/p&gt;

&lt;p&gt;The following packages are used in this application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;"net/http"&lt;/strong&gt;: This is a native Go package that provides HTTP client and server implementations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;"github.com/golang-jwt/jwt/v4"&lt;/strong&gt;: This package provides the implementation of JWTs (JSON Web Tokens), which are used for user authentication.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;"github.com/gorilla/mux"&lt;/strong&gt;: This package is a powerful URL router and dispatcher. It's used to route incoming HTTP requests to their corresponding handler functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;"github.com/joho/godotenv"&lt;/strong&gt;: This package is used to read environment variables from a .env file, which is a common method for configuration in development environments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;"encoding/json"&lt;/strong&gt;: This is a native Go package that's used for encoding and decoding JSON.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;"os"&lt;/strong&gt; and &lt;strong&gt;"time"&lt;/strong&gt;: These are native Go packages used for operating system functionality and time manipulation respectively.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;"github.com/sirupsen/logrus"&lt;/strong&gt;: This package is a flexible logging library. It's used for logging debug information, errors, and general server events.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All code is available at &lt;strong&gt;&lt;a href="https://github.com/mffonseca/golang-jwt-authentication"&gt;https://github.com/mffonseca/golang-jwt-authentication&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
