Skip to content

Commit dc474ee

Browse files
committed
chore: initial proxy setup
1 parent ecd10f0 commit dc474ee

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed

go.mod

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
module golang-template
22

33
go 1.20
4+
5+
require github.com/gofiber/fiber/v2 v2.51.0
6+
7+
require (
8+
github.com/andybalholm/brotli v1.0.6 // indirect
9+
github.com/google/uuid v1.4.0 // indirect
10+
github.com/klauspost/compress v1.17.3 // indirect
11+
github.com/mattn/go-colorable v0.1.13 // indirect
12+
github.com/mattn/go-isatty v0.0.20 // indirect
13+
github.com/mattn/go-runewidth v0.0.15 // indirect
14+
github.com/rivo/uniseg v0.2.0 // indirect
15+
github.com/valyala/bytebufferpool v1.0.0 // indirect
16+
github.com/valyala/fasthttp v1.51.0 // indirect
17+
github.com/valyala/tcplisten v1.0.0 // indirect
18+
golang.org/x/sys v0.14.0 // indirect
19+
)

go.sum

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
2+
github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
3+
github.com/gofiber/fiber/v2 v2.51.0 h1:JNACcZy5e2tGApWB2QrRpenTWn0fq0hkFm6k0C86gKQ=
4+
github.com/gofiber/fiber/v2 v2.51.0/go.mod h1:xaQRZQJGqnKOQnbQw+ltvku3/h8QxvNi8o6JiJ7Ll0U=
5+
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
6+
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7+
github.com/klauspost/compress v1.17.3 h1:qkRjuerhUU1EmXLYGkSH6EZL+vPSxIrYjLNAK4slzwA=
8+
github.com/klauspost/compress v1.17.3/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
9+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
10+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
11+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
12+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
13+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
14+
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
15+
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
16+
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
17+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
18+
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
19+
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
20+
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
21+
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
22+
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
23+
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
24+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
25+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
26+
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
27+
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

main.go

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,60 @@
11
package main
22

3+
import (
4+
"fmt"
5+
"io"
6+
"log"
7+
"net/http"
8+
"strings"
9+
10+
"github.com/gofiber/fiber/v2"
11+
)
12+
13+
func getProtocol(target string) string {
14+
if strings.Contains(target, ":443") {
15+
return "https"
16+
} else {
17+
return "http"
18+
}
19+
}
20+
321
func main() {
4-
print("鬼を捕まえる準備ができました !")
22+
app := fiber.New()
23+
24+
app.All("*", func (c *fiber.Ctx) error {
25+
// headers := c.Request().Header
26+
27+
// Iterate over all headers and print them
28+
// headers.VisitAll(func(key, value []byte) {
29+
// c.Response().Header.Add(string(key), string(value))
30+
// })
31+
url := c.Request().URI()
32+
println(string(url.FullURI()))
33+
target := string(url.LastPathSegment())
34+
protocol := getProtocol(target)
35+
formatted := fmt.Sprintf("%s://%s", protocol, target)
36+
37+
println(formatted)
38+
39+
target_response, err := http.Get(formatted)
40+
41+
if err != nil {
42+
return c.SendStatus(400)
43+
}
44+
45+
// Iterate over all headers and print them
46+
for key, values := range target_response.Header {
47+
for _, value := range values {
48+
c.Response().Header.Add(string(key), string(value))
49+
}
50+
}
51+
52+
defer target_response.Body.Close()
53+
c.Status(target_response.StatusCode)
54+
// c.Response().Header.Add()
55+
body, _ := io.ReadAll(target_response.Body)
56+
return c.Send(body)
57+
})
58+
59+
log.Fatal(app.Listen(":3000"))
560
}

0 commit comments

Comments
 (0)