Skip to content

Commit

Permalink
Merge pull request #61 from goavega-software/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sn123 authored Dec 7, 2023
2 parents 852f034 + dfe7f20 commit 0d4faee
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 11 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Mustard has 4 components:
- Mustard relies on dotenv for setting configuration values like API keys etc. There's a sample .env.example file which needs to be renamed as .env with all keys set.
- Mustard relies on cron to fire events on schedule but also exposes an API to fire jobs immediately (POST /api/nudge). This API is used by the Vue client to get the data on first run instead of waiting for the events to fire on schedule.
- Since v0.2 Mustard also supports consuming Kafka topics and forwarding those events over Server Sent Events. More details are under Kafka section.
- Mustard supports multiple dashboards which are laidout in `config/config.json`. Each dashboard should have a unique id and is accessible over `/dashboard/{id}` URL.
- Starting v0.7.0 Mustard supports configuration in Yaml format in `config/config.yml`. This takes precedence over json file if both are found in the directory.

### First steps

Expand All @@ -31,7 +33,7 @@ $ go build
$ ./mustard
```
Navigate to http://localhost:8090/dashboard. Default port is 8090 unless overridden.
Navigate to http://localhost:8090/dashboard/{id}. Default port is 8090 unless overridden.
## Quick start
Expand Down
76 changes: 76 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
dashboards:
- id: ""
widgets:
- component: TextWidget
class:
- x1 y2
props:
eventId: bsGenerator
background: "#ffdb58"
state:
bsGenerator:
title: Y
subtitle: X
- component: TextWidget
class:
- x2 y4
props:
eventId: jotd
state:
jotd:
title: Y
subtitle: X
- component: Clock
class:
- x1 y2
props:
eventId: clockWidget
clockOneTz: America/Los_Angeles
clockThreeTz: America/New_York
state:
clockWidget: {}
jobs:
- name: jotd
schedule: "@every 1h"
api:
url: https://v2.jokeapi.dev/joke/Programming?blacklistFlags=nsfw,religious,political,racist,sexist,explicit&type=single
method: GET
transform: >
[
{
"operation": "shift",
"spec": {
"data.title": "joke",
"data.subtitle": "category"
}
},
{
"operation": "default",
"spec": {
"event": "jotd",
"data.background": "#ccc"
}
}
]
- name: bsgenerator
schedule: "@every 1h"
api:
url: https://corporatebs-generator.sameerkumar.website/
method: GET
transform: >
[
{
"operation": "shift",
"spec": {
"data.title": "phrase"
}
},
{
"operation": "default",
"spec": {
"event": "bsGenerator"
}
}
]
authorization: "${MyKey}"
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ require (
github.com/segmentio/kafka-go v0.3.6
github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/qntfy/kazaam.v3 v3.4.9/go.mod h1:Wd/NtL7lla1KLeVKvET8CWojg+DmX0tDUC6J+ut61Z0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
42 changes: 32 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"

_ "github.com/joho/godotenv/autoload"
"gopkg.in/yaml.v3"

"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
Expand Down Expand Up @@ -52,18 +53,41 @@ func installGist(gistID string) {
gist.Install()
}

func readConfig() []byte {
jsonFile, err := os.Open("./config/config.json")
if err != nil {
func readConfig() configuration {
// if config.yaml is present we use that first
var fileContent *os.File
var byteContent []byte
var result configuration
isYaml := true
_, err := os.Stat("./config/config.yml")
if os.IsNotExist(err) {
fileContent, err = os.Open("./config/config.json")
isYaml = false
} else {
fileContent, err = os.Open("./config/config.yml")
}
if err != nil && !os.IsNotExist(err) {
log.Println(err)
return []byte("[]")
byteContent = []byte("[]")
json.Unmarshal(byteContent, &result)
return result
}
bytes, err := ioutil.ReadAll(jsonFile)
byteContent, err = ioutil.ReadAll(fileContent)
if err != nil {
log.Println(err)
return []byte("[]")
byteContent = []byte("[]")
json.Unmarshal(byteContent, &result)
return result
}
return bytes
if isYaml {
err = yaml.Unmarshal(byteContent, &result)
if err != nil {
log.Println(err)
}
return result
}
json.Unmarshal(byteContent, &result)
return result
}

func main() {
Expand All @@ -86,9 +110,7 @@ func main() {
eventListener := events.EventListener{URL: os.Getenv("KAFKA_URL"), Topic: os.Getenv("KAFKA_TOPIC"), GroupID: "mustard"}
eventListener.Start()
// read config to get widgets
config := readConfig()
var result configuration
json.Unmarshal([]byte(config), &result)
result := readConfig()
mustardcore.GetFactory().Process(result.Jobs)

defer eventsManager.Destroy()
Expand Down

0 comments on commit 0d4faee

Please sign in to comment.