package main import ( "fmt" "log" "net/http" "strings" "net" "bufio" ) func handler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") w.Header().Set("Expires", "0") tmp := strings.Split(r.URL.Path, "/"); fmt.Println(tmp); if len(tmp[1]) == 6 { s := tmp[1]; fmt.Println(tmp[1]); conn, err := net.Dial("tcp", "localhost:5555"); if err != nil { log.Fatal(err); } fmt.Println(s); fmt.Fprintf(conn, "{\"type\": 2, \"url\": \"%s\"}", s); res, _ := bufio.NewReader(conn).ReadBytes('\n'); fmt.Println(string(res)); http.Redirect(w, r, string(res), http.StatusPermanentRedirect); }else{ //fmt.Fprintf(w, "oi", r.URL.Path[1:]); } } func main() { // page := &Page{Title: "Redirect", Body: []byte("Redirecting...")}; fmt.Println("Port 5556"); server := &http.Server{ Addr: "localhost:5556", Handler: http.HandlerFunc(handler), }; server.SetKeepAlivesEnabled(false); //http.HandleFunc("/", handler); log.Fatal(server.ListenAndServe()); }