Building a web application in Go

Create a web application using Mux in go.

First import the http and mux and in main function create the handler and run the server in any specified port(in this example we are running in 8080)

package main

import (


func main() {
    //mux router
    r := mux.NewRouter()
    r.HandleFunc("/", HomeHandler)
    http.Handle("/", r)
    // running on port 8080
    log.Fatal(http.ListenAndServe(":8080", nil))
func HomeHandler(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("Welcome to Home page.\n"))