-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest_import.go
56 lines (43 loc) · 968 Bytes
/
request_import.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"log"
//"time"
//"strconv"
"encoding/json"
"io/ioutil"
"net/http"
"github.com/julienschmidt/httprouter"
)
func newExportUnit(r *http.Request) (*exportUnit, error) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return nil, err
}
defer r.Body.Close()
eu := &exportUnit{}
err = json.Unmarshal(body, eu)
return eu, err
}
func cacheImport(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
eu, err := newExportUnit(r)
if err != nil {
log.Println(err)
e := newException("InvalidJsonPayloadException", "Invalid json payload")
e.Extended["more"] = fmt.Sprintf("%s", err)
e.write(w)
return
}
importop := &writeOp{
done: make(chan bool),
app: eu.AppName,
key: eu.Key,
val: eu.Value,
ttl: eu.TTL,
ct: eu.CreatedAt,
}
//timeit_start := time.Now().UnixNano()
//LOCAL WRITE
mainCache.Imports <- importop
//<-importop.done //CAN THIS LINE BE REMOVED FOR PERFORMANCE?
}