summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorKeuin <[email protected]>2023-07-29 21:20:12 +0800
committerKeuin <[email protected]>2023-07-29 21:20:12 +0800
commit110301a975e43739192577166d089e28c22ae266 (patch)
treee655e00876b0140aa9ad431824765cd1c8371899 /main.go
parente72342b0027752dc93e57ebec99c4eb9a8aa8efe (diff)
Add API server
Diffstat (limited to 'main.go')
-rw-r--r--main.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/main.go b/main.go
index 90e0d6a..e50dbba 100644
--- a/main.go
+++ b/main.go
@@ -9,6 +9,7 @@ import (
"context"
"fmt"
"github.com/akamensky/argparse"
+ "github.com/keuin/slbr/api"
"github.com/keuin/slbr/logging"
"github.com/keuin/slbr/recording"
"github.com/keuin/slbr/types"
@@ -153,7 +154,7 @@ func getTasks() (tasks []recording.TaskConfig) {
func main() {
logger := log.Default()
taskConfigs := getTasks()
- tasks := make([]recording.RunningTask, len(taskConfigs))
+ tasks := make([]*recording.RunningTask, len(taskConfigs))
wg := sync.WaitGroup{}
ctxTasks, cancelTasks := context.WithCancel(context.Background())
@@ -170,6 +171,21 @@ func main() {
}
fmt.Println("")
+ apiAddr := os.Getenv("BIND_ADDR")
+ if apiAddr == "" {
+ apiAddr = ":8080"
+ }
+ apiAgent := &agentImpl{
+ tasks: &tasks,
+ }
+ go func() {
+ logger.Println("Starting API server...")
+ err := api.StartServer(apiAddr, apiAgent)
+ if err != nil {
+ logger.Fatalf("Failed to start API server: %v", err)
+ }
+ }()
+
logger.Printf("Starting tasks...")
for i := range tasks {