Support services aliasing

This commit is contained in:
LittleSheep 2024-08-17 23:43:21 +08:00
parent 63ea5e848f
commit 5dbe1cf80d
2 changed files with 9 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package api package api
import ( import (
"github.com/spf13/viper"
"strings" "strings"
"git.solsynth.dev/hydrogen/dealer/pkg/internal/directory" "git.solsynth.dev/hydrogen/dealer/pkg/internal/directory"
@ -25,6 +26,11 @@ func listExistsService(c *fiber.Ctx) error {
func forwardServiceRequest(c *fiber.Ctx) error { func forwardServiceRequest(c *fiber.Ctx) error {
serviceType := c.Params("service") serviceType := c.Params("service")
aliasingMap := viper.GetStringMapString("services.alias")
if val, ok := aliasingMap[serviceType]; ok {
serviceType = val
}
service := directory.GetServiceInstanceByType(serviceType) service := directory.GetServiceInstanceByType(serviceType)
if service == nil || service.HttpAddr == nil { if service == nil || service.HttpAddr == nil {

View File

@ -36,3 +36,6 @@ cookie_samesite = "Lax"
access_token_duration = 300 access_token_duration = 300
refresh_token_duration = 2592000 refresh_token_duration = 2592000
[services]
alias = { id = "auth", uc = "files", co = "interactive", im = "messagings" }