Skip to content

Instantly share code, notes, and snippets.

@joeywas
Created November 18, 2025 03:59
Show Gist options
  • Select an option

  • Save joeywas/5df27d7286719e2580057e360f7c199c to your computer and use it in GitHub Desktop.

Select an option

Save joeywas/5df27d7286719e2580057e360f7c199c to your computer and use it in GitHub Desktop.
golang httprouter example
package main
import (
//"errors"
"fmt"
//"io"
"net/http"
"strings"
"github.com/julienschmidt/httprouter"
)
func handleRequest(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if r.URL.Query().Has("url") {
urlfrompath := strings.Replace(ps.ByName("string"), "/qr/", "", 1)
fmt.Fprintf(w, "https:/%s\n", urlfrompath)
} else {
fmt.Fprintf(w, "%s\n", strings.TrimPrefix(ps.ByName("string"), "/"))
}
}
func main() {
router := httprouter.New()
router.GET("/qr/*string", handleRequest) // Catch all paths
http.ListenAndServe(":8080", router)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment