The Go library can be used by importing the flux
package into your project.
To install the library, start by downloading the flux.zip
file from the panel. Then, extract the contents of the zip file into the vendor
directory of your project.
The file structure should look like this:
|- your-project
| |- vendor
| | |- flux
| | | |- flux.go
| | | |- go.mod
| ...
To initialize the Flux SDK, call the Init
function with your application ID.
flux := flux.Init("your-application-id")
To authenticate a user, call the Authenticate
method with the user’s license key and an optional hardware ID.
auth, err := flux.Authenticate(license, hwid)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Authenticated:", auth)
To get a field from the authenticated response, call the GetField
method with the field name and its data type.
expiresAt, err := flux.GetField("expiresAt", "int")
To get a variable from the server, call the GetVariable
method with the variable name and its data type.
str, err := flux.GetVariable("variable-name", "string")
To download a variable from the server, call the DownloadVariable
method with the variable name.
data, err := flux.DownloadVariable("file")
if err != nil {
fmt.Println("Error:", err)
return
}
err = ioutil.WriteFile("file.bin", data, 0644)
if err != nil {
fmt.Println("Error:", err)
return
}
Here’s a complete example using the Flux SDK.
package main
import (
"flux"
"fmt"
"io/ioutil"
)
func main() {
flux := flux.Init("your-application-id")
// Get an unauthenticated variable
welcomeStr, err := flux.GetVariable("welcome-str", "string")
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println(welcomeStr)
var license string
fmt.Print("Enter license: ")
fmt.Scan(&license)
auth, err := flux.Authenticate(license, get_hwid())
if err != nil {
fmt.Println("Error:", err)
return
}
expiresAt, err := flux.GetField("expiresAt", "int")
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Expires:", expiresAt)
// Get an authenticated variable
str, err := flux.GetVariable("secret", "string")
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Authenticated Variable:", str)
data, err := flux.DownloadVariable("file")
if err != nil {
fmt.Println("Error:", err)
return
}
err = ioutil.WriteFile("file.bin", data, 0644)
if err != nil {
fmt.Println("Error:", err)
return
}
}