This tells Go:
“This is the main program. Start running from here.”
The engine of a car
The main door of a house
Every Go program must have this.
import ( "fmt" "net/http" )
💡 Meaning: We are borrowing tools made by Go.
Tool Why we need it fmt To print messages net/http To build a web server
Like:
Borrowing a stove to cook
Borrowing a phone to talk
func homePage(w http.ResponseWriter, r *http.Request) {
💡 Meaning: This line says:
“When anyone visits my website, run this function.”
Part Meaning func Making a function (a helper machine) homePage Name of the function w Used to send a reply to the browser r Used to read what the user asked
fmt.Fprintln(w, "Hello! This is my first Go server!")
💡 Meaning: This line says:
“Send this text to the visitor’s browser.”
So when user opens:
They will see:
Hello! This is my first Go server!
}
💡 Meaning: The work of this function is completed.
func main() {
💡 Meaning: This is the starting point of your program. Go always starts running from main().
http.HandleFunc("/", homePage)
💡 Meaning: This tells Go:
“When someone visits / (home page), run homePage function.”
Symbol Meaning / Home page (like google.com/) homePage The function to run
http.ListenAndServe(":8080", nil)
💡 Meaning: This tells Go:
“Start a web server on port 8080 and keep it running.”
So now your website is available at:
Your computer becomes a mini website hosting machine ✅
}
Download from:
✅ Step 2 — Create a file
Create a file:
main.go
Paste the code inside it.
✅ Step 3 — Run in terminal go run main.go
✅ Step 4 — Open browser
Visit:
Hello from Go server!
🎉 YOU JUST CREATED A WEB SERVER 🎉