The application consists in outputting a bash command to a buffer. The catch: the arguments are url
s.
Which is working for simple cases, like: "duckduckgo". I.e., http://localhost:8080/free-riding/duckduckgo
works perfectly.
Output:
#[1]DuckDuckGo (HTML)
[2]About DuckDuckGo
____________________ Submit
References
1. https://duckduckgo.com/opensearch_html_v2.xml
2. https://duckduckgo.com/about.html
But, http://localhost:8080/free-riding/www.estadao.com.br/politica/blog-do-fausto-macedo/dia-d-julgamento-bolsonaro-inelegivel-tse-reuniao-embaixadores/
will give:
Not Found.
Thus, how can I encode an url
-argument to be passed to a router
, using fasthttp
?
Here is the code,
package main
import (
"fmt"
"log"
"os/exec"
"github.com/fasthttp/router"
"github.com/valyala/fasthttp"
)
func Lynx(ctx *fasthttp.RequestCtx) {
var url string = ctx.UserValue("url").(string)
cmd := exec.Command("lynx", "--dump", url)
stdout, err := cmd.Output()
if err != nil {
log.Fatal(err)
return
}
fmt.Fprintf(ctx, "%s\n", stdout)
}
func main() {
r := router.New()
r.GET("/free-riding/{url}", Lynx)
log.Fatal(fasthttp.ListenAndServe(":8080", r.Handler))
}