<?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: twlmed212</title>
    <description>The latest articles on DEV Community by twlmed212 (@twlmed212).</description>
    <link>https://dev.to/twlmed212</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3270809%2Fff5c0096-e8b1-4b1a-a212-51a4883775fe.jpg</url>
      <title>DEV Community: twlmed212</title>
      <link>https://dev.to/twlmed212</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/twlmed212"/>
    <language>en</language>
    <item>
      <title>What I learned building a forum in Go with no frameworks</title>
      <dc:creator>twlmed212</dc:creator>
      <pubDate>Thu, 08 Oct 2026 14:20:03 +0000</pubDate>
      <link>https://dev.to/twlmed212/what-i-learned-building-a-forum-in-go-with-no-frameworks-1j7h</link>
      <guid>https://dev.to/twlmed212/what-i-learned-building-a-forum-in-go-with-no-frameworks-1j7h</guid>
      <description>&lt;p&gt;This was one of my first projects at &lt;strong&gt;Zone01 Oujda&lt;/strong&gt;. With a team of 4, we built a web forum where users can register, write posts in categories, comment, and like or dislike posts.&lt;/p&gt;

&lt;p&gt;The rules were strict:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Backend in &lt;strong&gt;Go&lt;/strong&gt;, using only the standard library (plus &lt;code&gt;sqlite3&lt;/code&gt;, &lt;code&gt;bcrypt&lt;/code&gt; and &lt;code&gt;uuid&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Database: &lt;strong&gt;SQLite&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No frontend frameworks&lt;/strong&gt;, only HTML, CSS and vanilla JavaScript&lt;/li&gt;
&lt;li&gt;The app must run in &lt;strong&gt;Docker&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At that time we were just starting out, so almost everything was new to us. Here are the main things I learned.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. You don't need a framework for routing
&lt;/h2&gt;

&lt;p&gt;Since Go 1.22, &lt;code&gt;net/http&lt;/code&gt; supports HTTP methods and path parameters in routes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HandleFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"POST /login"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;handlers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Login&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HandleFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/post/{id}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;handlers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetPost&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the handler, &lt;code&gt;r.PathValue("id")&lt;/code&gt; gives you the id. For a small project, this was all we needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Sessions and cookies are simpler than they look
&lt;/h2&gt;

&lt;p&gt;When a user logs in, we create a random token, save it in a &lt;code&gt;sessions&lt;/code&gt; table, and send it to the browser in a cookie:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;HttpOnly&lt;/code&gt;, so JavaScript can't read it&lt;/li&gt;
&lt;li&gt;An expiration date of 1 hour&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The subject also asked for &lt;strong&gt;one session per user&lt;/strong&gt;. Instead of checking this in Go, we let SQLite handle it with a trigger:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TRIGGER&lt;/span&gt; &lt;span class="n"&gt;one_session_per_user&lt;/span&gt;
&lt;span class="k"&gt;BEFORE&lt;/span&gt; &lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;sessions&lt;/span&gt;
&lt;span class="k"&gt;FOR&lt;/span&gt; &lt;span class="k"&gt;EACH&lt;/span&gt; &lt;span class="k"&gt;ROW&lt;/span&gt;
&lt;span class="k"&gt;BEGIN&lt;/span&gt;
    &lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sessions&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;NEW&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you log in on a new device, the old session is deleted automatically. This was the moment I understood that a database can do much more than store data.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Passwords are never stored as plain text
&lt;/h2&gt;

&lt;p&gt;We hashed passwords with &lt;code&gt;bcrypt&lt;/code&gt; before saving them. At login, &lt;code&gt;bcrypt.CompareHashAndPassword&lt;/code&gt; checks the password against the hash. It's simple, but it was my first real lesson in web security.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Vanilla JavaScript can do a lot
&lt;/h2&gt;

&lt;p&gt;Without React, we used &lt;code&gt;fetch&lt;/code&gt; to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Like and dislike posts without reloading the page&lt;/li&gt;
&lt;li&gt;Add comments&lt;/li&gt;
&lt;li&gt;Load more posts when you scroll (infinite scroll)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It was more code, but it showed me exactly what frameworks do for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Docker basics
&lt;/h2&gt;

&lt;p&gt;We used a &lt;strong&gt;multi-stage Dockerfile&lt;/strong&gt;. The first stage compiles the Go program. The second stage is a small Alpine image that only contains the binary, the templates and the database. The final image is much smaller than one with the whole Go toolchain.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Working as a team of 4
&lt;/h2&gt;

&lt;p&gt;We made 149 commits, many merges, and a few painful conflicts. The biggest lesson: agree on the folder structure and naming &lt;strong&gt;before&lt;/strong&gt; writing code. We changed our structure halfway through, and it cost us time.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do differently
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Write tests from the start.&lt;/strong&gt; We tested everything by hand, and some bugs came back more than once.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep error handling in one place.&lt;/strong&gt; We repeated the same error code in many handlers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Building a forum without frameworks was slow, but it taught me how the web really works: HTTP, cookies, sessions, SQL and the DOM. Now when I use a framework, I understand what it does for me.&lt;/p&gt;

&lt;p&gt;The code is on GitHub: &lt;a href="https://github.com/twlmed212/Forum" rel="noopener noreferrer"&gt;github.com/twlmed212/Forum&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What was the first project that made you understand how the web works?&lt;/p&gt;

</description>
      <category>go</category>
      <category>webdev</category>
      <category>sqlite</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
