This repository has been archived on 2023-07-05. You can view files and clone it, but cannot push or open issues or pull requests.
clessy/stats/web.go

36 lines
822 B
Go
Raw Normal View History

2016-02-11 10:00:35 +00:00
package main
import (
"encoding/json"
"log"
"net/http"
)
func webStats(rw http.ResponseWriter, req *http.Request) {
err := json.NewEncoder(rw).Encode(stats)
if err != nil {
log.Println("[webStats] JSON Encoding error: " + err.Error())
}
}
func webUsers(rw http.ResponseWriter, req *http.Request) {
err := json.NewEncoder(rw).Encode(users)
if err != nil {
log.Println("[webUsers] JSON Encoding error: " + err.Error())
}
}
2016-02-13 22:53:07 +00:00
func webWords(rw http.ResponseWriter, req *http.Request) {
err := json.NewEncoder(rw).Encode(words)
if err != nil {
log.Println("[webWords] JSON Encoding error: " + err.Error())
}
}
2016-02-11 10:00:35 +00:00
func startWebServer(bindAddr string) {
http.HandleFunc("/stats", webStats)
2016-02-13 22:53:07 +00:00
http.HandleFunc("/users", webUserNames)
http.HandleFunc("/words", webUserWords)
2016-02-11 10:00:35 +00:00
http.ListenAndServe(bindAddr, nil)
}