package main import ( "crypto/tls" "fmt" "net/http" "net/http/httputil" "net/url" ) func main() { // Define the address and port for the proxy server proxyAddr := "localhost:8080" // Create a reverse proxy proxy := httputil.NewSingleHostReverseProxy(&url.URL{ Scheme: "https", Host: "example.com", // Replace with the target host you want to proxy }) // Create an HTTP server with a custom handler that routes requests to the reverse proxy server := &http.Server{ Addr: proxyAddr, Handler: http.HandlerFunc(handleRequest(proxy)), TLSConfig: &tls.Config{ // InsecureSkipVerify: true, // Only use this if you want to ignore SSL certificate validation }, } // Listen for incoming HTTPS connections fmt.Printf("Starting HTTPS proxy server on %s\n", proxyAddr) err := server.ListenAndServeTLS("cert.pem", "key.pem") if err != nil { fmt.Println("Error:", err) } } func handleRequest(proxy *httputil.ReverseProxy) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { // Forward the request to the reverse proxy proxy.ServeHTTP(w, r) } }