diff --git a/pkg/internal/models/destination.go b/pkg/internal/models/destination.go index f96ea1d..96c2524 100644 --- a/pkg/internal/models/destination.go +++ b/pkg/internal/models/destination.go @@ -6,7 +6,9 @@ const ( ) type BaseDestination struct { - Type string `json:"type"` + Type string `json:"type"` + Label string `json:"label"` + LabelRegion string `json:"label_region"` } type LocalDestination struct { diff --git a/pkg/internal/server/api/destinations.go b/pkg/internal/server/api/destinations.go new file mode 100644 index 0000000..b94223e --- /dev/null +++ b/pkg/internal/server/api/destinations.go @@ -0,0 +1,19 @@ +package api + +import ( + "git.solsynth.dev/hypernet/paperclip/pkg/internal/models" + "github.com/gofiber/fiber/v2" + jsoniter "github.com/json-iterator/go" + "github.com/spf13/viper" +) + +func listDestination(c *fiber.Ctx) error { + var destinations []models.LocalDestination + for _, value := range viper.GetStringSlice("destinations") { + var parsed models.LocalDestination + raw, _ := jsoniter.Marshal(value) + _ = jsoniter.Unmarshal(raw, &parsed) + destinations = append(destinations, parsed) + } + return c.JSON(destinations) +} diff --git a/pkg/internal/server/api/index.go b/pkg/internal/server/api/index.go index afbd8be..c4154dc 100644 --- a/pkg/internal/server/api/index.go +++ b/pkg/internal/server/api/index.go @@ -6,10 +6,10 @@ import ( ) func MapAPIs(app *fiber.App, baseURL string) { - app.Get("/.well-known/destinations", getDestinations) - api := app.Group(baseURL).Name("API") { + api.Get("/destinations", listDestination) + boost := api.Group("/boosts").Name("Boosts API") { boost.Get("/", listBoostByUser) diff --git a/pkg/internal/server/api/well_known_api.go b/pkg/internal/server/api/well_known_api.go deleted file mode 100644 index 0f76679..0000000 --- a/pkg/internal/server/api/well_known_api.go +++ /dev/null @@ -1,18 +0,0 @@ -package api - -import ( - "github.com/gofiber/fiber/v2" - "github.com/spf13/viper" -) - -func getDestinations(c *fiber.Ctx) error { - var data []string - for key := range viper.GetStringMap("destinations") { - data = append(data, key) - } - - return c.JSON(fiber.Map{ - "data": data, - "preferred": viper.GetString("preferred_destination"), - }) -}