From 110301a975e43739192577166d089e28c22ae266 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 29 Jul 2023 21:20:12 +0800 Subject: Add API server --- api/agent/agent.go | 19 +++++++++++++++++++ api/server.go | 8 ++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 api/agent/agent.go (limited to 'api') diff --git a/api/agent/agent.go b/api/agent/agent.go new file mode 100644 index 0000000..52c5500 --- /dev/null +++ b/api/agent/agent.go @@ -0,0 +1,19 @@ +package agent + +import "github.com/keuin/slbr/types" + +type Agent interface { + GetTasks() []TaskInfo +} + +type TaskStatus string + +type LiveRoomInfo struct { + ID types.RoomId `json:"id"` + Title *string `json:"title"` +} + +type TaskInfo struct { + LiveRoom LiveRoomInfo `json:"live_room"` + Status string `json:"status"` +} diff --git a/api/server.go b/api/server.go index 4cfe8f4..32e3202 100644 --- a/api/server.go +++ b/api/server.go @@ -2,15 +2,19 @@ package api import ( "github.com/gofiber/fiber/v2" - "github.com/keuin/slbr/logging" + "github.com/keuin/slbr/api/agent" ) -func StartServer(logger logging.Logger, addr string) error { +func StartServer(addr string, a agent.Agent) error { app := fiber.New() app.Get("/", func(c *fiber.Ctx) error { return c.SendString("Hello, World!") }) + app.Get("/tasks", func(c *fiber.Ctx) error { + return c.JSON(a.GetTasks()) + }) + return app.Listen(addr) } -- cgit v1.2.3