8
9

More than 5 years have passed since last update.

golangのwebサーバでDirectoryIndexを使う

Last updated at Posted at 2014-07-22
document_root.go
package main

import (
    "fmt"
    "net/http"
    "runtime"
)

func main() {
    if runtime.GOOS == "windows" {
        http.Handle("/", http.FileServer(http.Dir("c:/")))
    } else {
        http.Handle("/", http.FileServer(http.Dir("/")))
    }
    fmt.Print("Listening 8080 port")
    //http.ListenAndServe(":8080", nil)
    http.ListenAndServe("127.0.0.1:8080", nil)
}

ファイル一覧を読み取り専用で取得できる。

8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9