home‎ > ‎go‎ > ‎

Go Nano Http Server

A micro light Http Server, which I use for serving web contents internally, mainly for Java DOCs rendering, and my daughter uses it for HTML5, CSS3 and JS rendering during development.

I have installed it in my GOLANG PATH so that it can be run from anywhere. 

This code has been derived from golang.org sample.

/*
  A Micro Lite Http File Server
  http://golang.org/pkg/net/http/#example_FileServer
  go build nano_httpd.go 
  ./nano_httpd --root="/home/ashish/ABLabs/AIAComponents"
*/
package main

import (
    "flag"
    "fmt"
"log"
"net/http"
)

func main() {
    inPort := flag.String("port","7070","Input Port Number, default 7070")
    flDir :=  flag.String("root", "~", "root content directory default is ~")
    flag.Parse()
     
    httpPort := ":" + *inPort
    fmt.Printf("Port %s, Doc Root [%s]\n",httpPort,*flDir)
     
// Simple static webserver:
log.Fatal(http.ListenAndServe(httpPort, http.FileServer(http.Dir(*flDir))))
}


Find the file attached below:

ċ
nano_httpd.go
(1k)
Ashish Banerjee,
Jan 23, 2015, 10:17 PM
Comments