1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
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());
}
|