@@ -22,146 +22,156 @@ func (result ActionResult) Json() ([]byte, error) {
22
22
return data , err
23
23
}
24
24
25
- func (action Action ) wrapMessage (data interface {}) []byte {
26
- sendAction := ActionResult {
25
+ func (action Action ) getResult (data interface {}) []byte {
26
+ resultAction := ActionResult {
27
27
Id : action .Id ,
28
28
Method : action .Method ,
29
29
Data : data ,
30
30
}
31
- res , _ := sendAction .Json ()
31
+ res , _ := resultAction .Json ()
32
32
return res
33
33
}
34
34
35
- func handleAction (action * Action , send func ([] byte )) {
35
+ func handleAction (action * Action , result func (data interface {} )) {
36
36
switch action .Method {
37
37
case initClashMethod :
38
38
data := action .Data .(string )
39
- send ( action . wrapMessage ( handleInitClash (data ) ))
39
+ result ( handleInitClash (data ))
40
40
return
41
41
case getIsInitMethod :
42
- send ( action . wrapMessage ( handleGetIsInit () ))
42
+ result ( handleGetIsInit ())
43
43
return
44
44
case forceGcMethod :
45
45
handleForceGc ()
46
- send ( action . wrapMessage ( true ) )
46
+ result ( true )
47
47
return
48
48
case shutdownMethod :
49
- send ( action . wrapMessage ( handleShutdown () ))
49
+ result ( handleShutdown ())
50
50
return
51
51
case validateConfigMethod :
52
52
data := []byte (action .Data .(string ))
53
- send ( action . wrapMessage ( handleValidateConfig (data ) ))
53
+ result ( handleValidateConfig (data ))
54
54
return
55
55
case updateConfigMethod :
56
56
data := []byte (action .Data .(string ))
57
- send ( action . wrapMessage ( handleUpdateConfig (data ) ))
57
+ result ( handleUpdateConfig (data ))
58
58
return
59
59
case getProxiesMethod :
60
- send ( action . wrapMessage ( handleGetProxies () ))
60
+ result ( handleGetProxies ())
61
61
return
62
62
case changeProxyMethod :
63
63
data := action .Data .(string )
64
64
handleChangeProxy (data , func (value string ) {
65
- send ( action . wrapMessage ( value ) )
65
+ result ( value )
66
66
})
67
67
return
68
68
case getTrafficMethod :
69
- send ( action . wrapMessage ( handleGetTraffic () ))
69
+ result ( handleGetTraffic ())
70
70
return
71
71
case getTotalTrafficMethod :
72
- send ( action . wrapMessage ( handleGetTotalTraffic () ))
72
+ result ( handleGetTotalTraffic ())
73
73
return
74
74
case resetTrafficMethod :
75
75
handleResetTraffic ()
76
- send ( action . wrapMessage ( true ) )
76
+ result ( true )
77
77
return
78
78
case asyncTestDelayMethod :
79
79
data := action .Data .(string )
80
80
handleAsyncTestDelay (data , func (value string ) {
81
- send ( action . wrapMessage ( value ) )
81
+ result ( value )
82
82
})
83
83
return
84
84
case getConnectionsMethod :
85
- send ( action . wrapMessage ( handleGetConnections () ))
85
+ result ( handleGetConnections ())
86
86
return
87
87
case closeConnectionsMethod :
88
- send ( action . wrapMessage ( handleCloseConnections () ))
88
+ result ( handleCloseConnections ())
89
89
return
90
90
case closeConnectionMethod :
91
91
id := action .Data .(string )
92
- send ( action . wrapMessage ( handleCloseConnection (id ) ))
92
+ result ( handleCloseConnection (id ))
93
93
return
94
94
case getExternalProvidersMethod :
95
- send ( action . wrapMessage ( handleGetExternalProviders () ))
95
+ result ( handleGetExternalProviders ())
96
96
return
97
97
case getExternalProviderMethod :
98
98
externalProviderName := action .Data .(string )
99
- send ( action . wrapMessage ( handleGetExternalProvider (externalProviderName ) ))
99
+ result ( handleGetExternalProvider (externalProviderName ))
100
100
case updateGeoDataMethod :
101
101
paramsString := action .Data .(string )
102
102
var params = map [string ]string {}
103
103
err := json .Unmarshal ([]byte (paramsString ), & params )
104
104
if err != nil {
105
- send ( action . wrapMessage ( err .Error () ))
105
+ result ( err .Error ())
106
106
return
107
107
}
108
108
geoType := params ["geo-type" ]
109
109
geoName := params ["geo-name" ]
110
110
handleUpdateGeoData (geoType , geoName , func (value string ) {
111
- send ( action . wrapMessage ( value ) )
111
+ result ( value )
112
112
})
113
113
return
114
114
case updateExternalProviderMethod :
115
115
providerName := action .Data .(string )
116
116
handleUpdateExternalProvider (providerName , func (value string ) {
117
- send ( action . wrapMessage ( value ) )
117
+ result ( value )
118
118
})
119
119
return
120
120
case sideLoadExternalProviderMethod :
121
121
paramsString := action .Data .(string )
122
122
var params = map [string ]string {}
123
123
err := json .Unmarshal ([]byte (paramsString ), & params )
124
124
if err != nil {
125
- send ( action . wrapMessage ( err .Error () ))
125
+ result ( err .Error ())
126
126
return
127
127
}
128
128
providerName := params ["providerName" ]
129
129
data := params ["data" ]
130
130
handleSideLoadExternalProvider (providerName , []byte (data ), func (value string ) {
131
- send ( action . wrapMessage ( value ) )
131
+ result ( value )
132
132
})
133
133
return
134
134
case startLogMethod :
135
135
handleStartLog ()
136
- send ( action . wrapMessage ( true ) )
136
+ result ( true )
137
137
return
138
138
case stopLogMethod :
139
139
handleStopLog ()
140
- send ( action . wrapMessage ( true ) )
140
+ result ( true )
141
141
return
142
142
case startListenerMethod :
143
- send ( action . wrapMessage ( handleStartListener () ))
143
+ result ( handleStartListener ())
144
144
return
145
145
case stopListenerMethod :
146
- send ( action . wrapMessage ( handleStopListener () ))
146
+ result ( handleStopListener ())
147
147
return
148
148
case getCountryCodeMethod :
149
149
ip := action .Data .(string )
150
150
handleGetCountryCode (ip , func (value string ) {
151
- send ( action . wrapMessage ( value ) )
151
+ result ( value )
152
152
})
153
153
return
154
154
case getMemoryMethod :
155
155
handleGetMemory (func (value string ) {
156
- send ( action . wrapMessage ( value ) )
156
+ result ( value )
157
157
})
158
158
return
159
+ case getProfileMethod :
160
+ profileId := action .Data .(string )
161
+ handleGetMemory (func (value string ) {
162
+ result (handleGetProfile (profileId ))
163
+ })
164
+ return
165
+ case setStateMethod :
166
+ data := action .Data .(string )
167
+ handleSetState (data )
168
+ result (true )
159
169
default :
160
- handle := nextHandle (action , send )
170
+ handle := nextHandle (action , result )
161
171
if handle {
162
172
return
163
173
} else {
164
- send (action .wrapMessage ( action . DefaultValue ) )
174
+ result (action .DefaultValue )
165
175
}
166
176
}
167
177
}
0 commit comments