MarsClient

package
v0.1.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

README

MarsClient

MarsClient 是連接 MarsCloud 的核心客戶端,負責登入、金鑰同步、服務註冊、資料寫入與查詢。

主要能力

  • 以帳密、token 或 key 登入
  • 自動維護伺服器 URL 清單
  • 取得 AES / RSA 安全金鑰
  • 註冊 service / properties / device
  • 寫入事件與資料
  • 查詢歷史資料與最新資料
  • 下載 OTA 檔案

主要型別

  • MarsClient
  • AsyncTaskCallback

常用函式

登入與連線:

  • Create() *MarsClient
  • Login(_url, _account, _pass string) bool
  • LoginWithProj(_url, _account, _pass, _proj string) bool
  • LoginByToken(_url, _token string) bool
  • LoginByKey(_url, _key string) bool
  • ReLogin() bool
  • GetServerURL() string

安全與註冊:

  • ResetSecurityKey() bool
  • RegistryService(_info string, _resetKey bool) bool
  • RegistryServiceProperties(_id string, _prop string) bool
  • RegistryDevice(_root *MarsJSON.JSONObject) bool

資料操作:

  • PutData(...) bool
  • PutDataAdv(...) bool
  • PutEvent(...) bool
  • GetDataByTime(...) *MarsJSON.JSONObject
  • GetLastData(...) *MarsJSON.JSONObject
  • DeleteData(...) bool

基本範例

client := MarsClient.Create()
if !client.LoginWithProj("https://marscloud.example.com", "<your-account>", "<your-password>", "<your-project>") {
    panic("login fail")
}

client.ResetSecurityKey()

相容性說明

  • HTTP 呼叫內部會帶 Authentication / Authorization header
  • 金鑰同步流程對齊舊版控制面鏈路:
    • login
    • get_security_key
    • registry
    • MQTT connect

注意事項

  • CallAPI() 的 _timeout 目前存在,但部分內部呼叫仍沿用預設逾時語意
  • 若要跑完整 service 啟動流程,通常由 MarsService 管理,不建議業務層自行重組整個 lifecycle

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AsyncTaskPollInterval = 2 * time.Second
View Source
var AsyncTaskTimeout = 5 * time.Minute

以下相容設定僅可於初始化時修改。

Functions

This section is empty.

Types

type AsyncTaskCallback

type AsyncTaskCallback func(_resp string) bool

-------------------------------------------------------------------------------------

type MarsClient

type MarsClient struct {
	ServerURLs []string

	ProjID    string
	AuthToken string
	Account   string
	Password  string
	SecretKey string

	EnableLoadBalance bool
	// contains filtered or unexported fields
}

-------------------------------------------------------------------------------------

func Create

func Create() *MarsClient

-------------------------------------------------------------------------------------

func (*MarsClient) AddSystemLog

func (_this *MarsClient) AddSystemLog(_type, _msg string) bool

-------------------------------------------------------------------------------------

func (*MarsClient) CallAPI

func (_this *MarsClient) CallAPI(_api string, _payload string, _timeout int) string

------------------------------------------------------------------------------------- CALL API -------------------------------------------------------------------------------------

func (*MarsClient) CallAPISpecify

func (_this *MarsClient) CallAPISpecify(_url string, _api string, _payload string, _timeout int) string

-------------------------------------------------------------------------------------

func (*MarsClient) DeleteData

func (_this *MarsClient) DeleteData(_uuid, _suid, _ukey string, _mqttPush bool) bool

-------------------------------------------------------------------------------------

func (*MarsClient) DeleteDataAdv

func (_this *MarsClient) DeleteDataAdv(_space, _owner, _uuid, _suid, _ukey string, _eventInfo *MarsJSON.JSONObject, _mqttPush bool) bool

-------------------------------------------------------------------------------------

func (*MarsClient) DownloadOTA

func (_this *MarsClient) DownloadOTA(_srcFile string, _destFile string, _packet string, _version string) bool

DownloadOTA 下載遠端更新檔並儲存為檔案

func (*MarsClient) GetAuthToken added in v0.1.23

func (c *MarsClient) GetAuthToken() string

GetAuthToken 安全讀取登入憑證。

func (*MarsClient) GetDataByTime

func (_this *MarsClient) GetDataByTime(_uuid string, _startTime int64, _endTime int64) *MarsJSON.JSONObject

-------------------------------------------------------------------------------------

func (*MarsClient) GetDataByTimeAdv

func (_this *MarsClient) GetDataByTimeAdv(_space, _owner, _uuid, _suid string, _start, _end int64, _compress bool) *MarsJSON.JSONObject

-------------------------------------------------------------------------------------

func (*MarsClient) GetLastData

func (_this *MarsClient) GetLastData(_uuid string, _suid string, _count int, _compress bool) *MarsJSON.JSONObject

-------------------------------------------------------------------------------------

func (*MarsClient) GetLastDataAdv

func (_this *MarsClient) GetLastDataAdv(_space, _owner, _uuid, _suid, _orderBy, _orderType string, _count int, _compress bool) *MarsJSON.JSONObject

-------------------------------------------------------------------------------------

func (*MarsClient) GetServerURL

func (_this *MarsClient) GetServerURL() string

-------------------------------------------------------------------------------------

func (*MarsClient) GetServerURLByIndex

func (_this *MarsClient) GetServerURLByIndex(_index int) string

-------------------------------------------------------------------------------------

func (*MarsClient) LocalLogin

func (_this *MarsClient) LocalLogin(_proj string) bool

------------------------------------------------------------------------------------- 基礎通訊與登入 -------------------------------------------------------------------------------------

func (*MarsClient) Login

func (_this *MarsClient) Login(_url string, _account string, _pass string) bool

------------------------------------------------------------------------------------- Login 基礎登入

func (*MarsClient) LoginByKey

func (_this *MarsClient) LoginByKey(_url string, _key string) bool

------------------------------------------------------------------------------------- LoginByKey 使用 Key 登入

func (*MarsClient) LoginByKeyWithProj

func (_this *MarsClient) LoginByKeyWithProj(_url string, _proj string, _key string) bool

------------------------------------------------------------------------------------- LoginByKeyWithProj 使用 Key 與專案 ID 登入

func (*MarsClient) LoginByToken

func (_this *MarsClient) LoginByToken(_url string, _token string) bool

------------------------------------------------------------------------------------- LoginByToken 使用現有 Token 登入

func (*MarsClient) LoginWithProj

func (_this *MarsClient) LoginWithProj(_url string, _account string, _pass string, _proj string) bool

------------------------------------------------------------------------------------- LoginWithProj 帶有專案 ID 的登入

func (*MarsClient) PushMail

func (_this *MarsClient) PushMail(_host *MarsJSON.JSONObject, _mail, _title, _msg string) bool

------------------------------------------------------------------------------------- 其他功能 -------------------------------------------------------------------------------------

func (*MarsClient) PutData

func (_this *MarsClient) PutData(_uuid string, _suid string, _data *MarsJSON.JSONObject) bool

------------------------------------------------------------------------------------- 資料存取 (Put/Get) -------------------------------------------------------------------------------------

func (*MarsClient) PutDataAdv

func (_this *MarsClient) PutDataAdv(_space, _owner, _uuid, _suid, _ukey string, _data *MarsJSON.JSONObject, _mqttPush bool) bool

-------------------------------------------------------------------------------------

func (*MarsClient) PutEvent

func (_this *MarsClient) PutEvent(_uuid string, _suid string, _data *MarsJSON.JSONObject) bool

-------------------------------------------------------------------------------------

func (*MarsClient) ReLogin

func (_this *MarsClient) ReLogin() bool

------------------------------------------------------------------------------------- ReLogin 重新執行登入流程

func (*MarsClient) RegistryDevice

func (_this *MarsClient) RegistryDevice(_root *MarsJSON.JSONObject) bool

-------------------------------------------------------------------------------------

func (*MarsClient) RegistryService

func (_this *MarsClient) RegistryService(_info string, _resetKey bool) bool

func (*MarsClient) RegistryServiceProperties

func (_this *MarsClient) RegistryServiceProperties(_id string, _prop string) bool

-------------------------------------------------------------------------------------

func (*MarsClient) ReportAsyncTask

func (_this *MarsClient) ReportAsyncTask(_taskID, _status string, _progress int) string

-------------------------------------------------------------------------------------

func (*MarsClient) ResetSecurityKey

func (_this *MarsClient) ResetSecurityKey() bool

------------------------------------------------------------------------------------- 安全性管理 -------------------------------------------------------------------------------------

func (*MarsClient) RunAsyncTask

func (c *MarsClient) RunAsyncTask(id, service, api string, payload *MarsJSON.JSONObject, callback AsyncTaskCallback)

RunAsyncTask 保留舊入口,預設五分鐘總期限。

func (*MarsClient) RunAsyncTaskWithContext added in v0.1.23

func (c *MarsClient) RunAsyncTaskWithContext(ctx context.Context, id, service, api string, payload *MarsJSON.JSONObject, callback AsyncTaskCallback) <-chan error

RunAsyncTaskWithContext 可取消等待與正在進行的 HTTP 請求。 結果通道送出一次結果後關閉;自訂 callback 必須自行保證返回。

func (*MarsClient) SendBroadcast

func (_this *MarsClient) SendBroadcast(_from string, _msg *MarsJSON.JSONObject) bool

-------------------------------------------------------------------------------------

func (*MarsClient) SetAuthToken added in v0.1.23

func (c *MarsClient) SetAuthToken(token string)

SetAuthToken 安全更新登入憑證。

func (*MarsClient) UnzipData

func (_this *MarsClient) UnzipData(_dataBase64 string) *MarsJSON.JSONObject

func (*MarsClient) UnzipDataHuge

func (_this *MarsClient) UnzipDataHuge(_dataBase64 string) []string

-------------------------------------------------------------------------------------

func (*MarsClient) UpdateServerURL

func (_this *MarsClient) UpdateServerURL()

------------------------------------------------------------------------------------- UpdateServerURL 更新負載平衡的伺服器清單

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL