morristech
4/5/2019 - 12:08 AM

static file server written in golang.

static file server written in golang.

package main

import (
	"log"
	"net/http"
)

func main() {
	log.Println("Server started. 0.0.0.0:8080")
	http.ListenAndServe(":8080", http.HandlerFunc(fileHandler))
}

func fileHandler(w http.ResponseWriter, r *http.Request) {
	fileServer := http.FileServer(http.Dir("static"))
	log.Printf("url: %s:%s. header = %s", r.Method, r.URL.Path, r.Header)
	fileServer.ServeHTTP(w, r)
}