go言語でファイルサーバ
の編集
http://java.boy.jp/pukiwiki/index.php?p=4a32e5c3
[
トップ
] [
編集
|
差分
|
履歴
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
Markdown
]
-- 雛形とするページ --
StringTemplate
<!-- markdown --> # go言語インストール https://go.dev/dl/ # ファイルサーバ package main import ( "fmt" "log" "net/http" ) func main() { fileServer := http.FileServer(http.Dir(".")) http.Handle("/", fileServer) fmt.Println("Server started on port 8080") log.Fatal(http.ListenAndServe(":8080", nil)) } # シンプルなカウントアップだけのエンドポイント package main import ( "fmt" "net/http" "sync" ) var counter int var mutex sync.Mutex func handler(w http.ResponseWriter, r *http.Request) { mutex.Lock() defer mutex.Unlock() counter++ fmt.Fprintf(w, "リクエスト回数: %d\n", counter) } func main() { http.HandleFunc("/countup", handler) // パスを "/countup" に変更 fmt.Println("サーバーを開始しました。http://localhost:8080/countup にアクセスしてください。") http.ListenAndServe(":8080", nil) }
SPAMではありません
タイムスタンプを変更しない
<!-- markdown --> # go言語インストール https://go.dev/dl/ # ファイルサーバ package main import ( "fmt" "log" "net/http" ) func main() { fileServer := http.FileServer(http.Dir(".")) http.Handle("/", fileServer) fmt.Println("Server started on port 8080") log.Fatal(http.ListenAndServe(":8080", nil)) } # シンプルなカウントアップだけのエンドポイント package main import ( "fmt" "net/http" "sync" ) var counter int var mutex sync.Mutex func handler(w http.ResponseWriter, r *http.Request) { mutex.Lock() defer mutex.Unlock() counter++ fmt.Fprintf(w, "リクエスト回数: %d\n", counter) } func main() { http.HandleFunc("/countup", handler) // パスを "/countup" に変更 fmt.Println("サーバーを開始しました。http://localhost:8080/countup にアクセスしてください。") http.ListenAndServe(":8080", nil) }
テキスト整形のルールを表示する