<!-- 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)
    }

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   最終更新のRSS