代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
package main

import (
	"io"
	"log"
	"net/http"
)

func main() {
	http.Handle("/dir", http.StripPrefix("/dir", http.FileServer(http.Dir("/usr/local/"))))
	err := http.ListenAndServe(":8080", nil)
	//err := http.ListenAndServe(":8080",http.FileServer(http.Dir("/usr/local/")))
	if err != nil {
		log.Fatal("...")
	}
}

参考

  1. FileServer文档