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

Method ApplyPattern

internal/server/patterns.go:98–125  ·  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

96// @Security ApiKeyAuth
97// @Router /patterns/{name}/apply [post]
98func (h *PatternsHandler) ApplyPattern(c *gin.Context) {
99 name := c.Param("name")
100 if rejectUnsafePatternName(c, name) {
101 return
102 }
103
104 var request PatternApplyRequest
105 if err := c.ShouldBindJSON(&request); err != nil {
106 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
107 return
108 }
109
110 // Merge query parameters with request body variables (body takes precedence)
111 variables := make(map[string]string)
112 for key, values := range c.Request.URL.Query() {
113 if len(values) > 0 {
114 variables[key] = values[0]
115 }
116 }
117 maps.Copy(variables, request.Variables)
118
119 pattern, err := h.patterns.GetApplyVariables(name, variables, request.Input)
120 if err != nil {
121 storageError(c, err)
122 return
123 }
124 c.JSON(http.StatusOK, pattern)
125}

Callers

nothing calls this directly

Calls 4

rejectUnsafePatternNameFunction · 0.85
storageErrorFunction · 0.85
GetApplyVariablesMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected