-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
40 lines (33 loc) · 774 Bytes
/
server.go
File metadata and controls
40 lines (33 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"os"
"fmt"
"net/http"
"io/ioutil"
)
func handleRequest(w http.ResponseWriter, r *http.Request) {
//Parse Data
body, error := ioutil.ReadAll(r.Body)
fileName := r.Header["Filename"]
deviceID := r.Header["Identifier"]
dirPath := fmt.Sprint("logs/", deviceID[0], "/")
filePath := fmt.Sprint(dirPath, fileName[0]);
if error != nil {
http.Error(w, error.Error(), 500)
}
//Write File
os.MkdirAll(dirPath, os.ModePerm)
out, error := os.Create(filePath);
if error != nil {
http.Error(w, error.Error(), 500)
}
_, error = out.Write([]byte(body));
if error != nil {
http.Error(w, error.Error(), 500)
}
fmt.Print("Recieved File\n")
}
func main() {
http.HandleFunc("/", handleRequest)
http.ListenAndServe(":8000", nil)
}