support lieral
parent
e200f2a6eb
commit
9d3da9265c
15
main.go
15
main.go
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
|
|
@ -36,6 +37,17 @@ func main() {
|
||||||
for len(link) == 0 {
|
for len(link) == 0 {
|
||||||
link = string(links[rand.Intn(len(links))])
|
link = string(links[rand.Intn(len(links))])
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(link, "http") {
|
||||||
|
serveHTTP(w, r, proxy, link)
|
||||||
|
} else if strings.HasPrefix(link, "literal://") {
|
||||||
|
w.Write([]byte(strings.TrimPrefix(link, "literal://") + "\n"))
|
||||||
|
}
|
||||||
|
})); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func serveHTTP(w http.ResponseWriter, r *http.Request, proxy bool, link string) {
|
||||||
if proxy {
|
if proxy {
|
||||||
resp, err := http.Get(link)
|
resp, err := http.Get(link)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -51,7 +63,4 @@ func main() {
|
||||||
} else {
|
} else {
|
||||||
http.Redirect(w, r, link, http.StatusTemporaryRedirect)
|
http.Redirect(w, r, link, http.StatusTemporaryRedirect)
|
||||||
}
|
}
|
||||||
})); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
literal://hello world
|
||||||
|
literal://foo bar
|
||||||
Loading…
Reference in New Issue