May 30, 2025 10:56 PM (GMT+6)
I don’t have any prior experience with go. Though I did some api development which was pretty basic. I am proficient in OOP and have little to no experience with functional programming language. So, WHY AM I DOING IT ?
Answer is to push myself out of my comfort zone.
First of all I got to find out that go was created by the same creator of B and C language. I do have some prior experience with C which may help me understand go. I went through go’s documentation and some tutorials. And I believe I got a good grasp on some fundamentals like functions (higher order function & first class function), closures and how structure is similar to classes but without methods. Here we can add functions to a structure just like C.
so initially I want to develop a go server. That gives a response to a http request.
Let’s get going,
I created a folder named backend. And created a file named main.go. Now let’s google stuff.
For reference, Here’s my main.go in it’s initial state :
package main
import "fmt"
func main() {
}
func init() {
fmt.Println("Initalizing server..")
}
So I found out a magic command which is
go doc <any standard library name>
This command opens doc file for that library name. Feels like old good days.
I searched for two things
go doc net
go doc net/http
http has many sections. one of them is # Servers section. through which I got to know about
ListenAndServe & HandleFunc and now my main.go looks like
package main
import (
"fmt"
"log"
"net/http"
)
var port string = ":8080"
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, world")
})
log.Fatal(http.ListenAndServe(port, nil))
}
func init() {
fmt.Println("Initalizing server..")
fmt.Println("serving at : <http://localhost>", port)
}
So, that was easy !
now this line bothers me :