DEV Community

Collins Kipruto
Collins Kipruto

Posted on

Go Journey – Day 2: Building My First Web Application in Go 🚀





I shared my experience building my first RESTful API in Go. This week, I took the next step in my Go journey by learning how to build web applications.

The next milestone? Working with relational databases in Go.

My goal with this series is simple: learn Go one step at a time while documenting the journey. By the end, I want to have enough knowledge to build a complete web application—from the backend to the frontend—and I hope others who are learning Go can follow along too.

What I Learned This Week

This week was all about understanding how a web application works under the hood. Instead of just writing code, I focused on understanding the flow of a request and how different components fit together.

Here are some of the concepts I covered.

  1. Storing Data with Structs

The first step was learning how to represent data using Go structs.

For the wiki application, each page was represented as a struct containing the page title and body.

type Page struct {
Title string
Body []byte
}

This became the foundation for everything else in the application.

  1. Saving Data

After creating the struct, I learned how to save a page to disk.

Each page is stored as a text file, using the page title as the filename. This gave me a better understanding of how Go handles file operations and methods.

  1. Loading Existing Pages

Saving data isn't enough—you also need to retrieve it.

I learned how to read the stored files back into memory so users can view pages that were previously created.

Although simple, this really helped me understand the flow of data in a web application.

Understanding net/http

One of the biggest topics this week was Go's net/http package.

I learned how HTTP requests move through the application and how Go uses handlers to respond to users.

Some of the things I explored included:

Creating routes
Handling requests and responses
Redirecting users when a page doesn't exist
Understanding http.ResponseWriter
Understanding *http.Request

Seeing how everything connects made the request-response cycle much clearer.

Template Caching

One of my favorite takeaways was learning about template caching.

At first, I was parsing HTML templates every single time a request came in.

func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
t, err := template.ParseFiles(tmpl + ".html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

err = t.Execute(w, p)
if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
}
Enter fullscreen mode Exit fullscreen mode

}

Then I learned there's a much better approach.

Instead of repeatedly reading template files from disk, you can parse them once when the application starts.

var templates = template.Must(
template.ParseFiles("edit.html", "view.html"),
)

This small change improves efficiency and is considered the better practice.

It was a great reminder that writing code isn't just about making it work—it's also about making it perform well.

Path Validation and Closures

Another interesting concept I encountered was path validation.

I learned how validating request paths prevents users from accessing invalid or unexpected routes.

While implementing this, I was introduced to closures in Go—something I had heard about before but hadn't used in a practical example.

That's definitely a topic I plan to explore further.

My Biggest Takeaway

This week taught me that building web applications is about much more than displaying pages.

It's about understanding:

how data flows,
how requests are processed,
how files are managed,
how templates are rendered efficiently,
and how to build applications that are secure and maintainable.

Every chapter makes me appreciate Go's simplicity even more.

What's Next?

The next chapter of my journey is working with relational databases in Go.

Once I have that in place, I'll begin combining everything I've learned into a larger project instead of isolated tutorials.

If you're also learning Go, I'd love to hear what you're currently building or what topics you think I should explore next.

Thanks for reading, and see you in the next chapter!

Happy coding! 🚀

Series: Learning Go in Public

✅ Part 1: Building My First RESTful API
✅ Part 2: Building My First Web Application
🔜 Part 3: Working with Relational Databases in Go

Top comments (0)