forked from yahoo/gryffin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serialize.go
53 lines (45 loc) · 936 Bytes
/
serialize.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
// Copyright 2015, Yahoo Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gryffin
import (
"encoding/json"
"net/http"
)
func NewScanFromJson(b []byte) *Scan {
// ensure we got a memory store..
if memoryStore == nil {
memoryStore = NewGryffinStore()
}
var scan Scan
json.Unmarshal(b, &scan)
return &scan
}
func (s *Scan) Json() []byte {
ss := &SerializableScan{
s,
&SerializableRequest{s.Request, ""},
&SerializableResponse{
s.Response,
&SerializableRequest{s.Request, ""},
},
}
b, err := json.Marshal(ss)
if err != nil {
s.Error("Json", err)
}
return b
}
type SerializableScan struct {
*Scan
Request *SerializableRequest
Response *SerializableResponse
}
type SerializableResponse struct {
*http.Response
Request *SerializableRequest
}
type SerializableRequest struct {
*http.Request
Cancel string
}