Hello World

To run this tutorial, you only need a Golang development environment, and the Dashborg SDK. You’ll also need a rudimentary knowledge of HTML (basic syntax, tags, and attributes).

Dashborg is designed to be simple to get started with. The most basic concept in Dashborg is the App. An App has a small configuration, HTML (layout), and an optional runtime to send data to the UI and respond to UI events.

Let’s jump right in and define a very simple static Dashborg App. We’ll create two files “demo.go” for the logic, and “demo.html” for our layout.

<app ui="dashborg">
  <h1>Hello World</h1>
</app>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package main

import (
    "fmt"

    "github.com/sawka/dashborg-go-sdk/pkg/dash"
)

func main() {
    config := &dash.Config{AutoKeygen: true, AnonAcc: true}
    client, err := dash.ConnectClient(config)
    if err != nil {
        fmt.Printf("Error connecting Dashborg client: %v\n", err)
        return
    }
    app := client.AppClient().NewApp("demo")
    app.SetOfflineAccess(true)
    app.WatchHtmlFile("./demo.html", nil)
    err = client.AppClient().WriteApp(app)
    if err != nil {
        fmt.Printf("Error writing app: %v\n", err)
        return
    }
}

Now run the program:

go run demo.go

You should see output that looks similar to:

DashborgCloudClient KeyFile:dashborg-client.key CertFile:dashborg-client.crt AccId:[ACC-ID] SHA-256:[PUBLIC-KEY-SHA256]
DashborgCloudClient Connected, AccId:[ACC-ID] Zone:default
Dashborg App Link [demo]: https://acc-[ACC-ID].console.dashborg.net/app/demo?jwt=[LONG-JWT-KEY]

Copy and paste your app link (console.dashborg.net) into your browser to see your live dashboard!

Hello World Dashboard App

That’s it, you’ve created a new Dashborg account and defined your first Dashborg App!

Notes

  • Because we called app.SetOfflineAccess(true) you can view our app even when our program is not running. If we set this to false, then the app will only be accessible when your program is running.
  • We used app.WatchHtmlFile() to set our HTML. This creates a fsnotify watcher and re-uploads your HTML anytime it detects a change while your program is running. For production you can use app.SetHtmlFromFile(fileName string) or app.SetHtml(htmlStr string).
  • All hosted Dashborg apps are secure. The generated JWT token provides access for 24-hours (configurable). After claiming your account, you can set up alternate authentication methods like simple passwords or logins.

Next - Adding a Button