mirror of
https://github.com/danielmiessler/fabric
synced 2024-11-08 07:11:06 +00:00
36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
package restapi
|
|
|
|
import (
|
|
"github.com/danielmiessler/fabric/plugins/db/fsdb"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
// PatternsHandler defines the handler for patterns-related operations
|
|
type PatternsHandler struct {
|
|
*StorageHandler[fsdb.Pattern]
|
|
patterns *fsdb.PatternsEntity
|
|
}
|
|
|
|
// NewPatternsHandler creates a new PatternsHandler
|
|
func NewPatternsHandler(r *gin.Engine, patterns *fsdb.PatternsEntity) (ret *PatternsHandler) {
|
|
ret = &PatternsHandler{
|
|
StorageHandler: NewStorageHandler[fsdb.Pattern](r, "patterns", patterns), patterns: patterns}
|
|
|
|
// TODO: Add custom, replacement routes here
|
|
//r.GET("/patterns/:name", ret.Get)
|
|
return
|
|
}
|
|
|
|
// Get handles the GET /patterns/:name route
|
|
func (h *PatternsHandler) Get(c *gin.Context) {
|
|
name := c.Param("name")
|
|
variables := make(map[string]string) // Assuming variables are passed somehow
|
|
pattern, err := h.patterns.GetApplyVariables(name, variables)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, pattern)
|
|
}
|