func homeHandler(w http.ResponseWriter, r *http.Request) { fmt.Println(r.URL.String()) // 404 for all other url path if r.URL.Path[1:] != "" { http.NotFound(w, r) return } r.ParseForm() enteredURL := r.FormValue("url") if enteredURL != "" { validURL, _ := url.Parse(enteredURL) // prepend http if not specified if validURL.Scheme == "" { validURL.Scheme = "http" } encodedURL, err := util.EncryptURL(validURL.String()) if err != nil { w.Write([]byte("build url failed:" + err.Error())) return } http.Redirect(w, r, "/p/"+encodedURL, 302) return } Assest.FileHandlerFunc("/assets/html/index.html")(w, r) }
// GenReqUrl 生成一个新的url地址 func (item *ProxyItem) GenReqUrl(urlReq string) (newURL string, encURL string, err error) { str := fmt.Sprintf("%d|%s", item.getServerTime(), urlReq) enURL, err := kxutil.EncryptURL(str) if err != nil { return "", "", err } return fmt.Sprintf("%s/p/%s", strings.TrimRight(item.Url, "/"), enURL), enURL, nil }
func helloHandler(w http.ResponseWriter, r *http.Request) { t, _ := util.EncryptURL(fmt.Sprintf("%d", time.Now().Unix())) w.Write([]byte(t)) }