Skip to content

Commit

Permalink
feat: refactor server startup and routing logic
Browse files Browse the repository at this point in the history
- Add the import statement for `github.com/gin-gonic/gin`
- Remove the log and run statements for the server startup
- Add error handling for server startup
- Add the `Reverse` function definition

Signed-off-by: appleboy <[email protected]>
  • Loading branch information
appleboy committed Feb 25, 2024
1 parent 9eeb75a commit 1a7e153
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions forward-proxy/main.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package main

import (
"github.com/gin-gonic/gin"
"io"
"net/http"
"net/http/httputil"
"net/url"

"github.com/gin-gonic/gin"
)

func main() {
r := gin.Default()

r.Use(ForwardMid)

//Create a catchall route
// Create a catchall route
r.Any("/*proxyPath", Reverse)

log.Info("启动http")
r.Run(":8888")
if err := r.Run(":8888"); err != nil {
panic(err)
}
}

func ForwardMid(c *gin.Context) {
Expand All @@ -41,13 +43,15 @@ func ForwardMid(c *gin.Context) {

c.Next()
}

func copyHeader(dst, src http.Header) {
for k, vv := range src {
for _, v := range vv {
dst.Add(k, v)
}
}
}

func Reverse(c *gin.Context) {
remote, _ := url.Parse("http://xxx.xxx.xxx")
proxy := httputil.NewSingleHostReverseProxy(remote)
Expand Down

0 comments on commit 1a7e153

Please sign in to comment.