PluginApi
The PluginApi
is the root 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 PluginApi
.
When the plugin is first loaded into the system, the system looks for the Init
function of the plugin's main
package. The PluginApi
object is then passed to the plugin's Init
function. From here, you can start configuring the routes and components of your plugin. An example of a plugin's init function:
package main
import (
sdkplugin "github.com/flarehotspot/sdk/api/plugin"
)
func main() {}
func Init(api sdkplugin.PluginApi) {
// You can start using the SDK here.
// You can configure your routes, define your plugin components
// and register items in the portal and admin nav menu, and more.
}
PluginApi Methods
The following are the available methods in PluginApi
.
Pkg
It returns the package
field defined in plugin.json.
Name
It returns the name
field defined in plugin.json.
Version
It returns the version
field defined in plugin.json.
Description
It returns the description
field defined in plugin.json.
Dir
It returns the absolute path of the plugin's installtion directory.
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 paramenter 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:
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"
SqlDb
It returns *sql.DB instance which is used to query, insert, update and delete database entities.
Acct
It returns the AccountsApi object which is used to access and modify the system admin accounts.
Http
It returns the HttpApi
object which is used to configure routes and serve HTTP requests.
Config
It returns the ConfigApi
object which is used to access and modify the system configuration.
Payments
It return the PaymentsApi
object which is used to create payment options or create system transactions.
InAppPurchases
It returns the InAppPurchasesApi
object which is used to create and manage in-app purchases.
Ads
It returns the AdsApi
object which is used to create and manage ads.
PluginsMgr
It returns the PluginsMgrApi
object which is used to manage plugins.
Network
It returns the NetworkApi
object which is used to manage the network.
DeviceHooks
It returns the DeviceHooksApi
object which is used to manage device registration hooks.
SessionsMgr
It returns the SessionsMgrApi object which is used to manage user sessions.
Uci
It returns the UciApi
object which is a wrapper to OpenWRT's UCI.
Themes
It returns the ThemesApi
object which is used to manage system UI themes.
Features
Returns the implement 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 |