MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / ApplyPattern

Method ApplyPattern

internal/server/patterns.go:76–100  ·  view source on GitHub ↗

ApplyPattern handles the POST /patterns/:name/apply route @Summary Apply pattern with variables @Description Apply a pattern with variable substitution @Tags patterns @Accept json @Produce json @Param name path string true "Pattern name" @Param request body PatternApplyRequest true "Pattern applicat

(c *gin.Context)

Source from the content-addressed store, hash-verified

74// @Security ApiKeyAuth
75// @Router /patterns/{name}/apply [post]
76func (h *PatternsHandler) ApplyPattern(c *gin.Context) {
77 name := c.Param("name")
78
79 var request PatternApplyRequest
80 if err := c.ShouldBindJSON(&request); err != nil {
81 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
82 return
83 }
84
85 // Merge query parameters with request body variables (body takes precedence)
86 variables := make(map[string]string)
87 for key, values := range c.Request.URL.Query() {
88 if len(values) > 0 {
89 variables[key] = values[0]
90 }
91 }
92 maps.Copy(variables, request.Variables)
93
94 pattern, err := h.patterns.GetApplyVariables(name, variables, request.Input)
95 if err != nil {
96 c.JSON(http.StatusInternalServerError, err.Error())
97 return
98 }
99 c.JSON(http.StatusOK, pattern)
100}

Callers

nothing calls this directly

Calls 2

ErrorMethod · 0.80
GetApplyVariablesMethod · 0.80

Tested by

no test coverage detected