package vistas import ( "bytes" "fmt" "net/http" "os/exec" "regexp" "strings" "github.com/gin-gonic/gin" ) func Buscador(c *gin.Context) { busqueda := c.PostForm("busqueda") //Sanitize "busqueda" busqueda = regexp.MustCompile(`[^a-zA-Z0-9ñÑáéíóú\- ]+`).ReplaceAllString(busqueda, "") cmd := exec.Command("rg", "-l", busqueda, "./letras") var out bytes.Buffer cmd.Stdout = &out err := cmd.Run() if err != nil { resultado := "Error buscando :(" fmt.Println(resultado) } res := "" atopadas := strings.Split(out.String(), "\n") if len(atopadas) > 0 { res = res + "" } // fmt.Println(res) c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(res)) }