-
-
Notifications
You must be signed in to change notification settings - Fork 709
Multi-Target Model Aliases and Provider Aggregation #716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| golang 1.25.5 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,6 +160,12 @@ func (h *Handler) PutConfigYAML(c *gin.Context) { | |
| return | ||
| } | ||
| h.cfg = newCfg | ||
|
|
||
| // Update global aliases from the new config | ||
| if newCfg.Aliases != nil { | ||
| util.SetAliases(newCfg.Aliases) | ||
| } | ||
|
|
||
| c.JSON(http.StatusOK, gin.H{"ok": true, "changed": []string{"config"}}) | ||
| } | ||
|
|
||
|
|
@@ -241,3 +247,81 @@ func (h *Handler) DeleteProxyURL(c *gin.Context) { | |
| h.cfg.ProxyURL = "" | ||
| h.persist(c) | ||
| } | ||
|
|
||
| // Aliases | ||
| func (h *Handler) GetAliases(c *gin.Context) { | ||
| aliases := h.cfg.Aliases | ||
| if aliases == nil { | ||
| aliases = make(map[string][]string) | ||
| } | ||
| c.JSON(200, gin.H{"aliases": aliases}) | ||
| } | ||
|
|
||
| func (h *Handler) PutAliases(c *gin.Context) { | ||
| var body struct { | ||
| Aliases *map[string][]string `json:"aliases"` | ||
| } | ||
| if err := c.ShouldBindJSON(&body); err != nil || body.Aliases == nil { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": "invalid body"}) | ||
| return | ||
| } | ||
| h.cfg.Aliases = *body.Aliases | ||
| h.persist(c) | ||
| // Update global aliases after persisting | ||
| if h.cfg.Aliases != nil { | ||
| util.SetAliases(h.cfg.Aliases) | ||
| } | ||
|
Comment on lines
+268
to
+273
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return value of h.cfg.Aliases = *body.Aliases
if !h.persist(c) {
return
}
// Update global aliases after persisting
if h.cfg.Aliases != nil {
util.SetAliases(h.cfg.Aliases)
} |
||
| } | ||
|
|
||
| func (h *Handler) PutAlias(c *gin.Context) { | ||
| alias := c.Param("alias") | ||
| if alias == "" { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": "missing alias"}) | ||
| return | ||
| } | ||
| var body struct { | ||
| Target *string `json:"target"` | ||
| Targets *[]string `json:"targets"` | ||
| } | ||
| if err := c.ShouldBindJSON(&body); err != nil { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": "invalid body"}) | ||
| return | ||
| } | ||
|
|
||
| var targets []string | ||
| if body.Targets != nil { | ||
| targets = *body.Targets | ||
| } else if body.Target != nil { | ||
| targets = []string{*body.Target} | ||
| } else { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": "missing target or targets"}) | ||
| return | ||
| } | ||
|
|
||
| if h.cfg.Aliases == nil { | ||
| h.cfg.Aliases = make(map[string][]string) | ||
| } | ||
| h.cfg.Aliases[alias] = targets | ||
| if !h.persist(c) { | ||
| return | ||
| } | ||
| // Update global aliases after persisting | ||
| util.SetAliases(h.cfg.Aliases) | ||
| c.JSON(200, gin.H{"alias": alias, "targets": targets}) | ||
| } | ||
|
|
||
| func (h *Handler) DeleteAlias(c *gin.Context) { | ||
| alias := c.Param("alias") | ||
| if alias == "" { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": "missing alias"}) | ||
| return | ||
| } | ||
| if h.cfg.Aliases != nil { | ||
| delete(h.cfg.Aliases, alias) | ||
| } | ||
| util.SetAliases(h.cfg.Aliases) | ||
| if !h.persist(c) { | ||
| return | ||
| } | ||
|
Comment on lines
+322
to
+325
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The order of operations in if !h.persist(c) {
return
}
util.SetAliases(h.cfg.Aliases) |
||
| c.JSON(200, gin.H{"deleted": alias}) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
payloadconfiguration section has been uncommented in this pull request. If this change is unrelated to the multi-target alias feature, it might be better to revert it or move it to a separate PR to keep this one focused on a single concern.