From 110301a975e43739192577166d089e28c22ae266 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 29 Jul 2023 21:20:12 +0800 Subject: Add API server --- main.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'main.go') 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 { -- cgit v1.2.3