diff options
author | Keuin <[email protected]> | 2023-07-29 21:20:12 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-07-29 21:20:12 +0800 |
commit | 110301a975e43739192577166d089e28c22ae266 (patch) | |
tree | e655e00876b0140aa9ad431824765cd1c8371899 /main.go | |
parent | e72342b0027752dc93e57ebec99c4eb9a8aa8efe (diff) |
Add API server
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -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 { |