Feb 24, 2017
Golang Web Development with Examples
How fast Go ( Golang ) is growing?http://www.tiobe.com/tiobe-index/ |
Because its open source and designed for building simple, fast, and reliable softwares.
Who is using Golang?
Check the list here https://github.com/golang/go/wiki/GoUsers
Writing Web Applications using Go
Go is a good language for building websites/web servers, Let's understand with few examples:-
1. Static Web Server in Go
2. Simple Hello Web Example
// hello-web.go
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "hello web")
})
http.ListenAndServe(":8080", nil)
}
3. Register a Route / Path
// routes.go
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/hi/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hi web")
})
http.ListenAndServe(":8080", nil)
}
Check more examples on Go Web Examples
By : Motyar+ @motyar