package
0.0.0-20220816064742-c4a05d444388
Repository: https://github.com/tolvmannen/digit.git
Documentation: pkg.go.dev
# Functions
In practice APIdispatcher doesn't need a termination signal, as it will just sit inside http.ListenAndServe, but we keep it for symmetry.
//func APIping(conf *Config) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
log.Printf("APIping: received /ping request from %s.\n", r.RemoteAddr)
tls := ""
if r.TLS != nil {
tls = "TLS "
}
decoder := json.NewDecoder(r.Body)
var pp PingPost
err := decoder.Decode(&pp)
if err != nil {
log.Println("APIping: error decoding ping post:", err)
}
pongs += 1
host, _ := os.Hostname()
response := PingResponse{
Time: time.Now(),
Client: r.RemoteAddr,
Message: fmt.Sprintf("%spong from sharkd @ %s", tls, host),
Pings: pp.Pings + 1,
Pongs: pongs}
w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(response)
if err != nil {
log.Printf("Error from Encoder: %v\n", err)
}
}
}
*/.
func SetupRouter(conf *Config) *mux.Router {.