From 203bd51f6dd336b4e35332f0e29ac5b5d80a792b Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Sun, 18 Feb 2024 12:31:17 +0330 Subject: [PATCH] Add warp account methods --- config/warp_account.go | 24 ++++++++++++++++++++++++ custom/custom.go | 12 ++++++++++++ mobile/mobile.go | 4 ++++ 3 files changed, 40 insertions(+) create mode 100644 config/warp_account.go diff --git a/config/warp_account.go b/config/warp_account.go new file mode 100644 index 0000000..38ccbe7 --- /dev/null +++ b/config/warp_account.go @@ -0,0 +1,24 @@ +package config + +import "encoding/json" + +type WarpAccount struct { + AccountID string `json:"account-id"` + AccessToken string `json:"access-token"` +} + +func GenerateWarpAccount(licenseKey string, accountId string, accessToken string) (string, error) { + data, _, _, err := GenerateWarpInfo(licenseKey, accountId, accessToken) + if err != nil { + return "", err + } + warpAccount := WarpAccount{ + AccountID: data.AccountID, + AccessToken: data.AccessToken, + } + accountJson, err := json.Marshal(warpAccount) + if err != nil { + return "", err + } + return string(accountJson), nil +} diff --git a/custom/custom.go b/custom/custom.go index 0b06a83..d0a6f76 100644 --- a/custom/custom.go +++ b/custom/custom.go @@ -295,4 +295,16 @@ func urlTest(groupTag *C.char) (CErr *C.char) { return C.CString("") } +//export generateWarpConfig +func generateWarpConfig(licenseKey *C.char, accountId *C.char, accessToken *C.char) (CResp *C.char) { + defer config.DeferPanicToError("generateWarpConfig", func(err error) { + CResp = C.CString(fmt.Sprint("error: ", err.Error())) + }) + account, err := config.GenerateWarpAccount(C.GoString(licenseKey), C.GoString(accountId), C.GoString(accessToken)) + if err != nil { + return C.CString(fmt.Sprint("error: ", err.Error())) + } + return C.CString(account) +} + func main() {} diff --git a/mobile/mobile.go b/mobile/mobile.go index 0dd9e86..29b34bf 100644 --- a/mobile/mobile.go +++ b/mobile/mobile.go @@ -36,3 +36,7 @@ func BuildConfig(path string, configOptionsJson string) (string, error) { } return config.BuildConfigJson(*configOptions, options) } + +func GenerateWarpConfig(licenseKey string, accountId string, accessToken string) (string, error) { + return config.GenerateWarpAccount(licenseKey, accountId, accessToken) +}