30 lines
486 B
Go
30 lines
486 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"sync"
|
|
)
|
|
|
|
var mu sync.Mutex
|
|
var count int
|
|
|
|
func main() {
|
|
http.HandleFunc("/", handler)
|
|
http.HandleFunc("/count", counter)
|
|
log.Fatal(http.ListenAndServe("localhost:8090", nil))
|
|
}
|
|
|
|
func handler(w http.ResponseWriter, r *http.Request) {
|
|
mu.Lock()
|
|
count++
|
|
mu.Unlock()
|
|
fmt.Fprintf(w, "URL.Path = %q\n", r.URL.Path)
|
|
}
|
|
func counter(w http.ResponseWriter, r *http.Request) {
|
|
mu.Lock()
|
|
fmt.Fprintf(w, "count: %d", count)
|
|
mu.Unlock()
|
|
}
|