Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial commit
  • Loading branch information
wrr14001 committed Feb 14, 2019
0 parents commit 95d18e7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
*.exe
.idea/*
2 changes: 2 additions & 0 deletions README.md
@@ -0,0 +1,2 @@
# gateway-server
This is a commit of skeleton code for the gateway server
6 changes: 6 additions & 0 deletions data-types.go
@@ -0,0 +1,6 @@
package main

type StampedReading struct {
Timestamp int
Value interface{}
}
27 changes: 27 additions & 0 deletions gateway.go
@@ -0,0 +1,27 @@
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)

func main() {
http.HandleFunc("/data", dataHandler)
if err := http.ListenAndServe(":8081", nil); err != nil {
fmt.Printf("Error serving 8081: %v", 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)
}

0 comments on commit 95d18e7

Please sign in to comment.