Skip to content
Permalink
563b3cceb4
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
45 lines (37 sloc) 1006 Bytes
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
// TODO: log to file
func main() {
http.HandleFunc("/data", dataHandler)
http.HandleFunc("/heartbeat", heartbeatHandler)
if err := http.ListenAndServeTLS(
":48820",
"/etc/pki/tls/certs/gateway.crt",
"/etc/pki/tls/private/gateway.key",
nil); err != nil {
fmt.Printf("Error serving TLS: %v\n", err)
}
}
func dataHandler(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Got data from: %v at %v\n", r.Header.Get("uuid"), r.Header.Get("time"))
body, _ := ioutil.ReadAll(r.Body)
var data map[string][]StampedReading
if err := json.Unmarshal(body, &data); err != nil {
fmt.Printf("Error unmarshalling body: %v\n", err)
} else {
fmt.Printf("Data received: %v\n", data)
}
w.WriteHeader(200)
}
func heartbeatHandler(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Got heartbeat from %v@%v at %v\n",
r.Header.Get(headerUUID),
r.RemoteAddr,
r.Header.Get(headerTimestamp))
w.WriteHeader(200)
}