Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Initial commit
- Loading branch information
0 parents
commit 95d18e7
Showing
4 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.exe | ||
.idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# gateway-server | ||
This is a commit of skeleton code for the gateway server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main | ||
|
||
type StampedReading struct { | ||
Timestamp int | ||
Value interface{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |