func RedirectURL(db *database.Database) httprouter.Handle {
	return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
		// Short URL named parameter
		shortURL := ps.ByName("short_url")
		// Search Database
		longURL, err := database.GetEntryDB(db, shortURL)
		if err != nil {
			// Database Error
			sendErrorResponse(w, r, http.StatusInternalServerError, err)
			return
		}
		// Long URL Not Found
		if longURL == "" {
			msg := fmt.Sprintf("URL %s Not Found", shortURL)
			jsonResp, err := createJSON(MessageResp{Message: msg})
			if err != nil {
				log.Fatal(err)
			}
			sendResponse(w, r, http.StatusNotFound, jsonResp)
			return
		}
		// Redirect using long URL found
		http.Redirect(w, r, longURL, http.StatusMovedPermanently)
	}
}
// RedirectURL handles requests for /redirect/:short_url path
RedirectURL handles requests for /redirect/:short_url path
// RedirectURL handles requests for / redirect / : short_url path
func RedirectURL(db *database.Database) httprouter.Handle {
	return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
		shortURL := ps.ByName("short_url")
		longURL, err := database.GetEntryDB(db, shortURL)
		if err != nil {
			sendErrorResponse(w, r, http.StatusInternalServerError, err)
			return
		}
		if longURL == "" {
			msg := fmt.Sprintf("URL %s Not Found", shortURL)
			jsonResp, err := createJSON(MessageResp{Message: msg})
			if err != nil {
				log.Fatal(err)
			}
			sendResponse(w, r, http.StatusNotFound, jsonResp)
			return
		}
		http.Redirect(w, r, longURL, http.StatusMovedPermanently)
	}
}
func RedirectURL ( db * database . Database ) httprouter . Handle { return func ( w http . ResponseWriter , r * http . Request , ps httprouter . Params ) { shortURL := ps . ByName ( " " ) longURL , err := database . GetEntryDB ( db , shortURL ) if err != nil { sendErrorResponse ( w , r , http . StatusInternalServerError , err ) return } if longURL == " " { msg := fmt . Sprintf ( " " , shortURL ) jsonResp , err := createJSON ( MessageResp { Message : msg } ) if err != nil { log . Fatal ( err ) } sendResponse ( w , r , http . StatusNotFound , jsonResp ) return } http . Redirect ( w , r , longURL , http . StatusMovedPermanently ) } }
RedirectURL handles requests for /redirect/:short_url path
RedirectURL handles requests for / redirect / : short_url path
// Short URL named parameter // Search Database // Database Error // Long URL Not Found // Redirect using long URL found