-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize lots of details
- Loading branch information
Showing
81 changed files
with
5,060 additions
and
2,028 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
const ( | ||
messageMethod Method = "message" | ||
initClashMethod Method = "initClash" | ||
getIsInitMethod Method = "getIsInit" | ||
forceGcMethod Method = "forceGc" | ||
shutdownMethod Method = "shutdown" | ||
validateConfigMethod Method = "validateConfig" | ||
updateConfigMethod Method = "updateConfig" | ||
getProxiesMethod Method = "getProxies" | ||
changeProxyMethod Method = "changeProxy" | ||
getTrafficMethod Method = "getTraffic" | ||
getTotalTrafficMethod Method = "getTotalTraffic" | ||
resetTrafficMethod Method = "resetTraffic" | ||
asyncTestDelayMethod Method = "asyncTestDelay" | ||
getConnectionsMethod Method = "getConnections" | ||
closeConnectionsMethod Method = "closeConnections" | ||
closeConnectionMethod Method = "closeConnection" | ||
getExternalProvidersMethod Method = "getExternalProviders" | ||
getExternalProviderMethod Method = "getExternalProvider" | ||
updateGeoDataMethod Method = "updateGeoData" | ||
updateExternalProviderMethod Method = "updateExternalProvider" | ||
sideLoadExternalProviderMethod Method = "sideLoadExternalProvider" | ||
startLogMethod Method = "startLog" | ||
stopLogMethod Method = "stopLog" | ||
startListenerMethod Method = "startListener" | ||
stopListenerMethod Method = "stopListener" | ||
) | ||
|
||
type Method string | ||
|
||
type Action struct { | ||
Id string `json:"id"` | ||
Method Method `json:"method"` | ||
Data interface{} `json:"data"` | ||
} | ||
|
||
func (action Action) Json() ([]byte, error) { | ||
data, err := json.Marshal(action) | ||
return data, err | ||
} | ||
|
||
func (action Action) callback(data interface{}) bool { | ||
if conn == nil { | ||
return false | ||
} | ||
sendAction := Action{ | ||
Id: action.Id, | ||
Method: action.Method, | ||
Data: data, | ||
} | ||
res, err := sendAction.Json() | ||
if err != nil { | ||
return false | ||
} | ||
_, err = conn.Write(append(res, []byte("\n")...)) | ||
if err != nil { | ||
return false | ||
} | ||
return true | ||
} |
Oops, something went wrong.