VOOZH about

URL: https://www.geeksforgeeks.org/go-language/how-to-build-a-simple-web-server-with-golang/

⇱ How to Build a Simple Web Server with Golang? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Build a Simple Web Server with Golang?

Last Updated : 23 Jul, 2025

Golang is a procedural programming language ideal to build simple, reliable, and efficient software. 

Creating Web Servers Using Golang: 

Initialize a project

Create a project folder with a .go file inside eg. server.go.

Directory structure:

👁 Image

The server.go file:

Run the server using the following command (make sure you're in the project directory):

go run server.go

Note:  You have to stop the server with Ctrl + C and restart via the same command whenever the server.go file is changed. 

Console:

👁 Image

Open the desired web browser and any of these URLs to verify if the server is running:

http://localhost:5000/ or http://localhost:5000/hi

Output:

👁 Image
👁 Image

Serving static files:

Create a static folder with all the static files.
Example directory structure:

👁 Image

Example static files:


  • The about.html file


Now Edit the server.go file:

Verifying if static files are served:

👁 Image
👁 Image
👁 Image
Comment
Article Tags:

Explore