IPluginApi
The IPluginApi
is the root Go interface of Flare Hotspot SDK. It provides access to methods used to manipulate system accounts, network devices, theme configuration, user sessions, payment system and more. Each plugin is provided with an instance of IPluginApi
.
When the plugin is first loaded into the system, the system looks for the Init
function of the plugin's main
package. The IPluginApi
instance is then passed to the plugin's Init
function. From there, you can start configuring the routes and components of your plugin. An example of a plugin's init function:
package main
import (
sdkapi "sdk/api"
)
// Required for main package
func main() {}
// Plugin entry point
func Init(api sdkapi.IPluginApi) {
// You can start using the SDK here.
// You can configure your routes, define your plugin components
// and register items in the portal and admin navigation menu, and more.
}
IPluginApi Methods
The following are the available methods in IPluginApi
.
Acct
It returns the IAccountsApi object which is used to access and modify the system admin accounts.
Ads
It returns the IAdsApi object which is used to create and manage ads.
Config
It returns the IConfigApi object which is used to access and modify the system configuration.
DeviceHooks
It returns the IDeviceHooksApi object which is used to manage device registration hooks.
Dir
It returns the absolute path of the plugin's installation directory.
Features
Returns the available features of the plugin.
Below are the available features and their descriptions:
Feature | Description |
---|---|
theme:admin |
Plugin provides an admin theme |
theme:portal |
Plugin provides a portal theme |
Http
It returns the IHttpApi object which is used to configure routes and serve HTTP requests.
InAppPurchases
It returns the IInAppPurchasesApi object which is used to create and manage in-app purchases.
Info
It returns the sdkutils.PluginInfo field defined in plugin.json.
info := api.Info()
fmt.Println(info)
// {
// Name: "My Plugin",
// Package: "com.mydomain.myplugin",
// Version: "0.0.1",
// Description: "My plugin description",
// SystemPackages: [],
// SDK: "1.0.0"
// }
Logger
It returns the ILoggerAPI object which is used to log events in a plugin.
Network
It returns the INetworkApi object which is used to manage the network.
Payments
It return the IPaymentsApi object which is used to create payment options or create system transactions.
PluginsMgr
It returns the IPluginsMgrApi object which is used to manage plugins.
Resource
It returns the absolute path of the file under the plugin's resource directory.
resource := api.Resource("/my-resource.txt")
fmt.Println(resource) // "/path/to/com.mydomain.myplugin/resources/my-resource.txt"
SessionsMgr
It returns the ISessionsMgrApi object which is used to manage user sessions.
SqlDb
It returns *sql.DB instance which is used to query, insert, update and delete database entities.
Themes
It returns the IThemesApi
object which is used to manage system UI themes.
Translate
It is a utility function used to convert a message key into a translated string. Example usage:
msg := api.Translate("info", "payment_received", "amount", 1.00)
fmt.Println(msg) // "Payment received USD 1.0.0"
In this example, given that the application language is set to en
, the system will look for the file resources/translations/en/info/payment_received.txt
inside your plugin directory. If the file is found, the system will use the contents of the file as the translation template.
Sometimes we want to put variables inside the translation message. In this example, we want to pass the amount
as a parameter to the message. We can do that by passing the amount param as key-value pairs to the Translate
method. Internally, the param pairs are converted into a type map[any]any
. To use the amount
param in the translation file, we'll enclose it with <%
and %>
delimiters (with dot prefix). Therefore the content of payment_received.txt
should be:
Uci
It returns the IUciApi object which is a wrapper to OpenWRT's UCI.