I have a Gorilla Mux router set up in Go. I have routes set up within that router, as well as function handlers associated with those routes. The router works perfectly, if you open a browser window and enter specific URLs. However, the problem I'm running into is what to do if the URL is entered on the command line. I know how to store the URL from the command line arguments, but I don't know how to forward the URL, stored as a URL variable in Go, to the router. Like, how do you call a route's function handler if the URL is given on the command line INSTEAD of entered via browser window?
Code:
u, err := url.Parse(os.Args[1])
if err != nil {
fmt.Println(err.Error())
}
host, port, _ := net.SplitHostPort(u.Host)
s := []string{":", port};
router := ANewRouter()
log.Fatal(http.ListenAndServe(strings.Join(s, ""), router))
//Route URL to router, somehow