* go言語インストール [#h4f69f72] https://go.dev/dl/ * ファイルサーバ [#fb7e3e3f] 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)) } * シンプルなカウントアップだけのエンドポイント [#efdfee99] 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) }