forked from fabric8-services/fabric8-wit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_information.go
56 lines (46 loc) · 1.21 KB
/
context_information.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 account
import (
"database/sql/driver"
"encoding/json"
"errors"
"reflect"
"github.com/fabric8-services/fabric8-wit/convert"
)
//ContextInformation a map for context information
type ContextInformation map[string]interface{}
// Ensure ContextInformation implements the Equaler interface
var _ convert.Equaler = ContextInformation{}
var _ convert.Equaler = (*ContextInformation)(nil)
// Equal returns true if two ContextInformation objects are equal; otherwise false is returned.
func (f ContextInformation) Equal(u convert.Equaler) bool {
other, ok := u.(ContextInformation)
if !ok {
return false
}
return reflect.DeepEqual(f, other)
}
func (f ContextInformation) Value() (driver.Value, error) {
return toBytes(f)
}
func (f *ContextInformation) Scan(src interface{}) error {
return fromBytes(src, f)
}
func toBytes(j interface{}) (driver.Value, error) {
if j == nil {
// log.Trace("returning null")
return nil, nil
}
res, error := json.Marshal(j)
return res, error
}
func fromBytes(src interface{}, target interface{}) error {
if src == nil {
target = nil
return nil
}
s, ok := src.([]byte)
if !ok {
return errors.New("Scan source was not string")
}
return json.Unmarshal(s, target)
}