<?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: antony</title>
    <description>The latest articles on DEV Community by antony (@antmusumba).</description>
    <link>https://dev.to/antmusumba</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%2F1790356%2Fd49146d0-c539-4b15-a4f1-182b9df71699.jpg</url>
      <title>DEV Community: antony</title>
      <link>https://dev.to/antmusumba</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/antmusumba"/>
    <language>en</language>
    <item>
      <title>Axios : Simplifying HTTP Requests in JavaScript</title>
      <dc:creator>antony</dc:creator>
      <pubDate>Thu, 29 May 2025 09:44:35 +0000</pubDate>
      <link>https://dev.to/antmusumba/axios-simplifying-http-requests-in-javascript-59b3</link>
      <guid>https://dev.to/antmusumba/axios-simplifying-http-requests-in-javascript-59b3</guid>
      <description>&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%2Fuvoess2cnb5morinxbc8.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%2Fuvoess2cnb5morinxbc8.png" alt="Image description" width="800" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whether you're building a weather app, consuming a RESTful API, or submitting form data, making HTTP requests is a fundamental part of modern web development. That's where &lt;strong&gt;Axios&lt;/strong&gt; shines. In this post, we’ll explore what Axios is, why it's useful, and how to get started with it.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Axios?
&lt;/h2&gt;

&lt;p&gt;Axios is a &lt;strong&gt;promise-based HTTP client&lt;/strong&gt; for the browser and Node.js. It makes it easy to send asynchronous HTTP requests to REST endpoints and perform CRUD operations (Create, Read, Update, Delete).&lt;/p&gt;

&lt;p&gt;You can think of Axios as an advanced version of &lt;code&gt;fetch()&lt;/code&gt;, but with a cleaner syntax and additional features.&lt;/p&gt;




&lt;h2&gt;
  
  
  Installing Axios
&lt;/h2&gt;

&lt;p&gt;bash&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or using yarn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a browser-based project, you can also use a CDN:&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;script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Making Your First Request&lt;/p&gt;

&lt;p&gt;Here’s a simple GET request to fetch some JSON data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import axios from 'axios';

axios.get('https://jsonplaceholder.typicode.com/posts')
  .then(response =&amp;gt; {
    console.log('Data:', response.data);
  })
  .catch(error =&amp;gt; {
    console.error('Error fetching data:', error);
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using Async/Await (Modern Approach):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fetchPosts = async () =&amp;gt; {
  try {
    const response = await axios.get('https://jsonplaceholder.typicode.com/posts');
    console.log('Data:', response.data);
  } catch (error) {
    console.error('Error:', error);
  }
};

fetchPosts();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Common HTTP Methods in Axios&lt;/p&gt;

&lt;p&gt;🔹 POST Request&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axios.post('https://example.com/api/posts', {
  title: 'New Post',
  body: 'This is the content.',
})
.then(response =&amp;gt; console.log(response.data))
.catch(error =&amp;gt; console.error(error));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 PUT Request&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axios.put('https://example.com/api/posts/1', {
  title: 'Updated Title',
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 DELETE Request&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axios.delete('https://example.com/api/posts/1');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sending Headers and Auth&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axios.get('https://api.example.com/user', {
  headers: {
    Authorization: 'Bearer your-token-here',
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creating Axios Instances&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const api = axios.create({
  baseURL: 'https://api.example.com',
  timeout: 1000,
  headers: { 'X-Custom-Header': 'foobar' }
});

api.get('/users');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Error Handling Best Practice&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 axios.get('/some-endpoint');
} catch (error) {
  if (error.response) {
    console.error('Server Error:', error.response.status);
  } else if (error.request) {
    console.error('No Response:', error.request);
  } else {
    console.error('Error', error.message);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Final Thoughts&lt;/p&gt;

&lt;p&gt;Axios is a powerful, battle-tested HTTP client that simplifies API communication in your JavaScript applications. Whether you're just starting out or building large-scale apps, Axios helps you write cleaner, more reliable code.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>"How to Write Clean and Maintainable Go Code"</title>
      <dc:creator>antony</dc:creator>
      <pubDate>Mon, 12 May 2025 06:16:58 +0000</pubDate>
      <link>https://dev.to/antmusumba/how-to-write-clean-and-maintainable-go-code-57p6</link>
      <guid>https://dev.to/antmusumba/how-to-write-clean-and-maintainable-go-code-57p6</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”&lt;br&gt;&lt;br&gt;
— Martin Fowler&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go is known for its simplicity — but clean, readable, and maintainable code doesn’t write itself. Whether you're building microservices, CLIs, or REST APIs, good Go code follows a few golden rules.&lt;/p&gt;

&lt;p&gt;Let’s walk through some &lt;strong&gt;practical tips&lt;/strong&gt; and &lt;strong&gt;real Go examples&lt;/strong&gt; to help you write &lt;strong&gt;cleaner and more idiomatic code&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 1. Use Clear, Descriptive Names
&lt;/h2&gt;

&lt;p&gt;Don’t try to be clever. Clarity beats brevity every time.&lt;/p&gt;

&lt;p&gt;❌ Bad:&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="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Good:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
func printUserID(userID int) {
    fmt.Println(userID)
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use camelCase for variables and functions. Reserve abbreviations for widely recognized terms like id, url, db.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚡ 2. Keep Functions Focused and Small
&lt;/h2&gt;

&lt;p&gt;One function = one responsibility. Break up logic when possible.&lt;/p&gt;

&lt;p&gt;❌ Bad:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func handleOrder(o Order) {
    validate(o)
    saveToDB(o)
    sendEmail(o)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Good:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func handleOrder(o Order) {
    if err := validate(o); err != nil {
        log.Println("Validation failed:", err)
        return
    }
    if err := storeOrder(o); err != nil {
        log.Println("Database error:", err)
        return
    }
    notifyCustomer(o)
}

func storeOrder(o Order) error {
    // logic to store in database
    return nil
}

func notifyCustomer(o Order) {
    // logic to send email
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Short, specific functions are easier to test and reuse.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧰 3. Format Code with gofmt or goimports
&lt;/h2&gt;

&lt;p&gt;No one wants to argue about tabs or spacing. Let the tools handle it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gofmt -w .
goimports -w .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They’ll format your code and manage your imports automatically. Clean code is also consistent code.&lt;/p&gt;

&lt;h2&gt;
  
  
  💬 4. Comment Why, Not What
&lt;/h2&gt;

&lt;p&gt;Don’t write comments for things that are self-explanatory. Focus on why a decision was made.&lt;/p&gt;

&lt;p&gt;❌ Bad:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Add two integers
func Add(x, y int) int {
    return x + y
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Better:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Add returns the sum of x and y.
// Used in the calculator to combine user inputs.
func Add(x, y int) int {
    return x + y
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use Go-style doc comments for exported functions and packages.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✅ 5. Write Tests (and Use Table-Driven Ones)
&lt;/h2&gt;

&lt;p&gt;Go makes testing easy — no excuses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "testing"

func TestAdd(t *testing.T) {
    tests := []struct {
        name string
        a, b int
        want int
    }{
        {"positive", 2, 3, 5},
        {"zero", 0, 0, 0},
        {"negative", -2, -3, -5},
    }

    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            if got := Add(tt.a, tt.b); got != tt.want {
                t.Errorf("Add(%d, %d) = %d; want %d", tt.a, tt.b, got, tt.want)
            }
        })
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use go test -cover to check coverage, and don’t forget BenchmarkX when performance matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  ♻️ 6. Don't Over-Abstract
&lt;/h2&gt;

&lt;p&gt;Avoid the trap of premature abstraction. Repetition isn’t always evil.&lt;/p&gt;

&lt;p&gt;❌ Over-abstracted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func logStart() { fmt.Println("starting...") }
func logEnd() { fmt.Println("ending...") }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Simple and reusable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func logPhase(phase string) {
    fmt.Printf("%s...\n", phase)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rule of thumb: if code is used more than twice and not tied to specific context — abstract it. Otherwise, duplicate with purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  📁 7. Structure Projects by Responsibility
&lt;/h2&gt;

&lt;p&gt;Go prefers flat, not deep. Organize based on what the code does.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/cmd/myapp         // app entry point
/internal/handlers // HTTP or CLI handlers
/internal/db       // DB logic
/pkg/utils         // reusable helpers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Avoid generic package names like common or base.&lt;/p&gt;

&lt;h2&gt;
  
  
  👥 8. Code Like Someone Else Will Maintain It
&lt;/h2&gt;

&lt;p&gt;Because someday… they will (and it might be you).&lt;/p&gt;

&lt;p&gt;Ask yourself:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Would a junior developer understand this code?

Is it easy to test or extend?

Are errors clear and helpful?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Your code should invite collaboration, not fear.&lt;br&gt;
🔚 Final Thoughts&lt;/p&gt;

&lt;p&gt;Writing clean Go code isn’t hard, but it requires discipline.&lt;/p&gt;

&lt;p&gt;✅ Use meaningful names&lt;br&gt;
✅ Write focused, testable functions&lt;br&gt;
✅ Format everything with gofmt&lt;br&gt;
✅ Test like you mean it&lt;br&gt;
✅ Comment only when needed&lt;br&gt;
✅ Keep it simple, not clever&lt;/p&gt;

&lt;p&gt;🗣️ What’s your favorite Go coding tip?&lt;br&gt;
Drop it in the comments!&lt;/p&gt;

&lt;p&gt;👉 Follow me for more Go content, real-world project tips, and practical dev advice.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why I Prefer Go Over Node.js for Backend Development</title>
      <dc:creator>antony</dc:creator>
      <pubDate>Wed, 07 May 2025 08:44:21 +0000</pubDate>
      <link>https://dev.to/antmusumba/why-i-prefer-go-over-nodejs-for-backend-development-ipp</link>
      <guid>https://dev.to/antmusumba/why-i-prefer-go-over-nodejs-for-backend-development-ipp</guid>
      <description>&lt;p&gt;As a softwar developer, choosing the right language and tools can make a huge difference in how efficiently you build, maintain, and scale applications. While Node.js is widely adopted in the backend world, I personally prefer Go (Golang) for several key reasons. Here's why.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ 1. Performance and Concurrency
&lt;/h2&gt;

&lt;p&gt;Go is a compiled language with built-in support for concurrency through goroutines and channels.&lt;/p&gt;

&lt;p&gt;Whether it's handling multiple HTTP requests or processing data-heavy tasks, Go offers consistent and high performance with minimal memory overhead. Its lightweight concurrency model is often simpler and more efficient than JavaScript’s event loop and async/await system.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏗️ 2. Static Typing = Fewer Runtime Surprises
&lt;/h2&gt;

&lt;p&gt;Go is statically typed, which helps catch errors early during compilation.&lt;/p&gt;

&lt;p&gt;In my experience, this leads to more robust code and reduces the kind of silent runtime bugs that can creep in with JavaScript's dynamic typing. Type safety also makes refactoring easier and safer.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔐 3. Simpler Dependency Management
&lt;/h2&gt;

&lt;p&gt;With Go modules (&lt;code&gt;go.mod&lt;/code&gt;, &lt;code&gt;go.sum&lt;/code&gt;), managing dependencies is straightforward and built right into the language.&lt;/p&gt;

&lt;p&gt;You don’t have to deal with complex dependency trees or massive &lt;code&gt;node_modules&lt;/code&gt; folders. It’s clean, fast, and predictable.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔧 4. Better Tooling Out of the Box
&lt;/h2&gt;

&lt;p&gt;Go comes with powerful built-in tools like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;go fmt&lt;/code&gt; for automatic code formatting&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;go run&lt;/code&gt; to quickly test code&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;go test&lt;/code&gt; for unit testing&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;go vet&lt;/code&gt; and &lt;code&gt;golint&lt;/code&gt; for catching subtle issues&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This strong tooling ecosystem promotes consistency and code quality without needing third-party packages.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧼 5. Minimalist, Clean Code
&lt;/h2&gt;

&lt;p&gt;Go encourages simplicity and readability. There's often "one right way" to do things, reducing bike-shedding and helping teams write uniform, maintainable code.&lt;/p&gt;

&lt;p&gt;In contrast, Node.js projects can get bloated with middleware, wrappers, and utilities for even simple tasks like routing or parsing JSON.&lt;/p&gt;




&lt;h2&gt;
  
  
  📉 6. Resource Efficiency
&lt;/h2&gt;

&lt;p&gt;Go binaries are compiled and self-contained, meaning they require no external runtime.&lt;/p&gt;

&lt;p&gt;This makes deployment easy—just build and ship the binary. No need for managing multiple layers of dependencies or setting up a runtime environment like you would with Node.js.&lt;/p&gt;




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

&lt;p&gt;Node.js has its strengths, especially for real-time applications and when working closely with frontend teams. But for clean, efficient, and scalable backend development, I’ve found Go to be more reliable, maintainable, and performant.&lt;/p&gt;




&lt;h2&gt;
  
  
  🗣️ What’s Your Take?
&lt;/h2&gt;

&lt;p&gt;Have you used Go or Node.js for backend development?&lt;br&gt;&lt;br&gt;
Which one do you prefer and why? I'd love to hear your thoughts in the comments!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building Web Applications with Go</title>
      <dc:creator>antony</dc:creator>
      <pubDate>Wed, 17 Jul 2024 12:34:35 +0000</pubDate>
      <link>https://dev.to/antmusumba/building-web-applications-with-go-5gme</link>
      <guid>https://dev.to/antmusumba/building-web-applications-with-go-5gme</guid>
      <description>&lt;p&gt;Go (Golang) is an excellent language for building web applications due to its simplicity, performance, and robust standard library. This guide will walk you through the process of creating a basic web application using Go, including setting up a web server, handling routes, and rendering HTML templates.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Setting Up Your Go Environment&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;First, ensure that you have Go installed on your machine. You can download and install it from the official Go website.&lt;/p&gt;

&lt;p&gt;Next, create a new directory for your project:&lt;br&gt;
&lt;/p&gt;

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

mkdir go-webapp
cd go-webapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize a new Go module:&lt;br&gt;
&lt;/p&gt;

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

go mod init go-webapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Creating a Basic Web Server&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Create a new file main.go and add the following code to set up a basic web server:&lt;/p&gt;

&lt;p&gt;go&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
package main

import (
    "fmt"
    "net/http"
)

func homePage(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Welcome to the Home Page!")
}

func main() {
    http.HandleFunc("/", homePage)
    fmt.Println("Server started at :8080")
    http.ListenAndServe(":8080", nil)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the server:&lt;br&gt;
&lt;/p&gt;

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

go run main.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open your browser and navigate to &lt;a href="http://localhost:8080" rel="noopener noreferrer"&gt;http://localhost:8080&lt;/a&gt; to see your web server in action.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Handling Routes&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To handle multiple routes, define additional handler functions:&lt;/p&gt;

&lt;p&gt;go&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
func aboutPage(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Welcome to the About Page!")
}

func main() {
    http.HandleFunc("/", homePage)
    http.HandleFunc("/about", aboutPage)
    fmt.Println("Server started at :8080")
    http.ListenAndServe(":8080", nil)
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Rendering HTML Templates&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Go’s html/template package allows you to render HTML templates. Create a templates directory and add an index.html file:&lt;/p&gt;

&lt;p&gt;html&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;!-- templates/index.html --&amp;gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;title&amp;gt;Home Page&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;{{ .Title }}&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;{{ .Content }}&amp;lt;/p&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Modify main.go to use the template:&lt;/p&gt;

&lt;p&gt;go&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "html/template"
    "net/http"
)

type PageData struct {
    Title   string
    Content string
}

func homePage(w http.ResponseWriter, r *http.Request) {
    data := PageData{
        Title:   "Home Page",
        Content: "Welcome to the Home Page!",
    }
    tmpl, _ := template.ParseFiles("templates/index.html")
    tmpl.Execute(w, data)
}

func aboutPage(w http.ResponseWriter, r *http.Request) {
    data := PageData{
        Title:   "About Page",
        Content: "Welcome to the About Page!",
    }
    tmpl, _ := template.ParseFiles("templates/index.html")
    tmpl.Execute(w, data)
}

func main() {
    http.HandleFunc("/", homePage)
    http.HandleFunc("/about", aboutPage)
    http.ListenAndServe(":8080", nil)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Using a Framework&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For more advanced web applications, consider using a Go web framework like Gin:&lt;/p&gt;

&lt;p&gt;Install Gin:&lt;br&gt;
&lt;/p&gt;

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

bash

go get -u github.com/gin-gonic/gin

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update main.go to use Gin:&lt;/p&gt;

&lt;p&gt;go&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "github.com/gin-gonic/gin"
)

func main() {
    r := gin.Default()

    r.GET("/", func(c *gin.Context) {
        c.JSON(200, gin.H{
            "message": "Welcome to the Home Page!",
        })
    })

    r.GET("/about", func(c *gin.Context) {
        c.JSON(200, gin.H{
            "message": "Welcome to the About Page!",
        })
    })

    r.Run(":8080")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Building web applications with Go is straightforward, thanks to its powerful standard library and the availability of frameworks like Gin. This guide provides a basic introduction, but there is much more to explore, including middleware, database integration, and authentication. Happy coding!&lt;/p&gt;

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