-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolicy_codec.go
executable file
·100 lines (81 loc) · 3.18 KB
/
policy_codec.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package campid
// type PolicyCodec interface {
// Decode(r io.Reader) (ActionPolicy, error)
// Encode(w io.Writer, s ActionPolicy) error
// }
// func CreatePolicyDocumentMapping() (*mapping.DocumentMapping, error) {
// var policyMapping = bleve.NewDocumentMapping()
// var textField = bleve.NewTextFieldMapping()
// textField.Analyzer = keyword.Name
// var scopeMapping = bleve.NewDocumentMapping()
// scopeMapping.AddFieldMappingsAt("Scope", textField)
// policyMapping.AddFieldMappingsAt("Id", textField)
// policyMapping.AddFieldMappingsAt("Name", textField)
// policyMapping.AddFieldMappingsAt("Permission", textField)
// return policyMapping, nil
// }
// func CreateLimitedPolicyDocumentMapping() (*mapping.DocumentMapping, error) {
// var policyMapping = bleve.NewDocumentMapping()
// var textField = bleve.NewTextFieldMapping()
// textField.Analyzer = keyword.Name
// policyMapping.AddFieldMappingsAt("Id", textField)
// policyMapping.AddFieldMappingsAt("Name", textField)
// return policyMapping, nil
// }
// // MsgPackPolicyCodec implements the PolicyCodec interface for using
// // the MsgPack Codec.
// type MsgPackPolicyCodec struct{}
// // Encode encodes giving session using the internal MsgPack format.
// // Returning provided data.
// func (gb *MsgPackPolicyCodec) Encode(w io.Writer, s ActionPolicy) error {
// if err := msgpack.NewEncoder(w).Encode(s); err != nil {
// return nerror.Wrap(err, "Failed to encode giving session")
// }
// return nil
// }
// // Decode decodes giving data into provided session instance.
// func (gb *MsgPackPolicyCodec) Decode(r io.Reader) (ActionPolicy, error) {
// var s ActionPolicy
// if err := msgpack.NewDecoder(r).Decode(&s); err != nil {
// return s, nerror.WrapOnly(err)
// }
// return s, nil
// }
// // JsonPolicyCodec implements the PolicyCodec interface for using
// // the Json Codec.
// type JsonPolicyCodec struct{}
// // Encode encodes giving session using the internal Json format.
// // Returning provided data.
// func (gb *JsonPolicyCodec) Encode(w io.Writer, s ActionPolicy) error {
// if err := json.NewEncoder(w).Encode(s); err != nil {
// return nerror.Wrap(err, "Failed to encode giving session")
// }
// return nil
// }
// // Decode decodes giving data into provided session instance.
// func (gb *JsonPolicyCodec) Decode(r io.Reader) (ActionPolicy, error) {
// var s ActionPolicy
// if err := json.NewDecoder(r).Decode(&s); err != nil {
// return s, nerror.WrapOnly(err)
// }
// return s, nil
// }
// // GobPolicyCodec implements the PolicyCodec interface for using
// // the gob Codec.
// type GobPolicyCodec struct{}
// // Encode encodes giving session using the internal gob format.
// // Returning provided data.
// func (gb *GobPolicyCodec) Encode(w io.Writer, s ActionPolicy) error {
// if err := gob.NewEncoder(w).Encode(s); err != nil {
// return nerror.Wrap(err, "Failed to encode giving session")
// }
// return nil
// }
// // Decode decodes giving data into provided session instance.
// func (gb *GobPolicyCodec) Decode(r io.Reader) (ActionPolicy, error) {
// var s ActionPolicy
// if err := gob.NewDecoder(r).Decode(&s); err != nil {
// return s, nerror.WrapOnly(err)
// }
// return s, nil
// }