[go-nuts] Re: HTTP Proxy in Go

2021-04-22 Thread Dang Dien

I recommend the fasthttp package. I have implemented an HTTP forwarding 
proxy in Go and use in production with high traffic (~40 rpm).
https://github.com/valyala/fasthttp
On Thursday, 22 April 2021 at 14:07:00 UTC+7 Van Fury wrote:

>
> Hi,
>
> I have to implement an HTTP forwarding proxy in Go which can be used in 
> production and need advice from Go experts. 
> Any advice like which Go library is best to use and other things to take 
> not of when implementing it.
>
> BR
> Abraham
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4ace5715-e44d-43b2-b762-3ebbb94c49d2n%40googlegroups.com.


[go-nuts] Re: HTTP Proxy in Go

2021-04-22 Thread Van Fury
Hi,

Thanks, I  have created these two proxy using the httputil. How can i send 
JSON request body from proxyA to proxyB.
Any help or idea?

ProxyA:

const (
  ServerB = ""
  Port = ""
)

func main() {
  // start server
  http.HandleFunc("/", proxyPass)
  log.Fatal(http.ListenAndServe(":" + Port, nil))
}

func proxyPass(res http.ResponseWriter, req  *http.Request) {
  
 // JSON message

msg := Data{ "key1": "v1", "key2":"v2"}
  
  url, _ := url.Parse(ServerB)
  proxy := httputil.NewSingleHostReverseProxy(url)
  proxy.ServeHTTP(res, req)
} 


For proxy B:

const (
  Server = ""
  Port = ""
)

func main() {
  // start server
  http.HandleFunc("/", proxyPass)
  log.Fatal(http.ListenAndServe(":" + Port, nil))
}

func proxyPass(res http.ResponseWriter, req  *http.Request) {
  // Decrypt Request here
  // ...

  url, _ := url.Parse(Server)
  proxy := httputil.NewSingleHostReverseProxy(url)
  proxy.ServeHTTP(res, req)
} 



On Thursday, April 22, 2021 at 4:55:26 PM UTC+3 wilk wrote:

> On 22-04-2021, Van Fury wrote:
> > --=_Part_322_998422299.1619075183467
> > Content-Type: multipart/alternative; 
> > boundary="=_Part_323_2099960923 <(209)%20996-0923>.1619075183467"
> >
> > --=_Part_323_2099960923 <(209)%20996-0923>.1619075183467
> > Content-Type: text/plain; charset="UTF-8"
> >
> >
> > Hi,
> >
> > I have to implement an HTTP forwarding proxy in Go which can be used in 
> > production and need advice from Go experts. 
> > Any advice like which Go library is best to use and other things to take 
> > not of when implementing it.
>
> I'm not an expert but I use the proxy of httputil without any issue. I'm
> using forwarding to legacy app with Go new app in front.
>
> -- 
> wilk
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/69400949-8dd7-42d6-9af4-c47787f72885n%40googlegroups.com.


[go-nuts] Re: HTTP Proxy in Go

2021-04-22 Thread wilk
On 22-04-2021, Van Fury wrote:
> --=_Part_322_998422299.1619075183467
> Content-Type: multipart/alternative; 
>   boundary="=_Part_323_2099960923.1619075183467"
>
> --=_Part_323_2099960923.1619075183467
> Content-Type: text/plain; charset="UTF-8"
>
>
> Hi,
>
> I have to implement an HTTP forwarding proxy in Go which can be used in 
> production and need advice from Go experts. 
> Any advice like which Go library is best to use and other things to take 
> not of when implementing it.

I'm not an expert but I use the proxy of httputil without any issue. I'm
using forwarding to legacy app with Go new app in front.

-- 
wilk

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/s5rv6u%24gir%241%40ciao.gmane.io.