shad-go/lectures/00-intro/counter/counter.go
Fedor Korotkiy c989b9f92e Fix lecture
2020-02-13 14:54:17 +03:00

29 lines
360 B
Go

package main
import (
"fmt"
"log"
"net/http"
"sync"
)
var (
counter int
mu sync.Mutex
)
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe("localhost:8000", nil))
}
func handler(w http.ResponseWriter, r *http.Request) {
var i int
mu.Lock()
i = counter
counter++
mu.Unlock()
fmt.Fprintf(w, "counter = %d\n", i)
}