Go: add context, part10 (#17417)

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-07-27 16:14:23 +08:00
committed by GitHub
parent cd846cc9d4
commit 49e6181eca
10 changed files with 94 additions and 79 deletions

View File

@@ -599,10 +599,11 @@ func (h *Handler) RestartService(c *gin.Context) {
// ListVariables handle list variables
func (h *Handler) ListVariables(c *gin.Context) {
ctx := c.Request.Context()
// Check if request has body content
if c.Request.ContentLength == 0 || c.Request.ContentLength == -1 {
// List all variables
variables, err := h.service.ListAllVariables()
variables, err := h.service.ListAllVariables(ctx)
if err != nil {
common.ErrorWithCode(c, common.CodeServerError, err.Error())
return
@@ -625,7 +626,7 @@ func (h *Handler) ListVariables(c *gin.Context) {
return
}
variable, err := h.service.GetVariable(req.VarName)
variable, err := h.service.GetVariable(ctx, req.VarName)
if err != nil {
common.ErrorWithCode(c, common.CodeServerError, err.Error())
return
@@ -647,7 +648,8 @@ func (h *Handler) ShowVariable(c *gin.Context) {
return
}
variable, err := h.service.GetVariable(varName)
ctx := c.Request.Context()
variable, err := h.service.GetVariable(ctx, varName)
if err != nil {
common.ErrorWithCode(c, common.CodeServerError, err.Error())
return
@@ -681,7 +683,8 @@ func (h *Handler) SetVariable(c *gin.Context) {
return
}
if err := h.service.SetVariable(req.VarName, req.VarValue); err != nil {
ctx := c.Request.Context()
if err := h.service.SetVariable(ctx, req.VarName, req.VarValue); err != nil {
common.ErrorWithCode(c, common.CodeServerError, err.Error())
return
}