forked from nitishm/go-rejson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
58 lines (49 loc) · 1.54 KB
/
options.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
package rjs
// ReJSONOption provides methods for the options used by various ReJSON commands
// It also abstracts options from the required parameters of the commands
//
// Like:
// JSON.GET, JSON.SET, JSON.ARRINDEX, JSON.ARRPOP
type ReJSONOption interface {
// Value returns the value of the option being used
Value() []interface{}
// MethodID returns the ID of the ReJSON Function defined in ReJSONCommands
// whose options are begins implemented
MethodID() ReJSONCommandID
}
// GetOption implements ReJSONOption for JSON.GET Method
// Get Options:
// * INDENT (with default set to a tab, '\t')
// * NEWLINE (with default set to a new line, '\n')
// * SPACE (with default set to a space, ' ')
// * NOESCAPE (a boolean type option)
type GetOption struct {
name string
Arg string
}
// MethodID returns the name of the method i.e. JSON.GET
func (g GetOption) MethodID() ReJSONCommandID {
return ReJSONCommandGET
}
// Value returns the value of the option being used
func (g GetOption) Value() []interface{} {
if g.name == GETOptionNOESCAPE.name {
return []interface{}{g.name}
}
return []interface{}{g.name, g.Arg}
}
func (g GetOption) SetValue(arg string) {
g.Arg = arg
}
// SetOption implements ReJSONOption for JSON.SET Method
// Set Options:
// * NX or XX
type SetOption string
// MethodID returns the name of the method i.e. JSON.SET
func (g SetOption) MethodID() ReJSONCommandID {
return ReJSONCommandSET
}
// Value returns the value of the option being used
func (g SetOption) Value() []interface{} {
return []interface{}{string(g)}
}