Skip to content

open-webtech/go-reverse-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reverse Proxy

This project is a lightweight and efficient reverse proxy module written in Go. Besides directly forwarding incoming requests to the specified remote, it allows for rewriting of the request path and defining custom headers.

Features

  • Easy configuration via a simple Go API.
  • Fine-grained control over which paths are passed through to the backend.
  • Support for rewriting of the request path.
  • Customizable request and response headers.
  • Integrated health check and load measurement functionality.

Installation

To install go-reverse-proxy, use the following command:

go get -u github.com/open-webtech/go-reverse-proxy

Usage

package main

import (
	"crypto/tls"
	"log"
	"net/http"

	reverseproxy "github.com/open-webtech/go-reverse-proxy"
)

func main() {
	rp, err := reverseproxy.New("http://my-backend:8000")
	if err != nil {
		log.Fatal(err)
	}
	rp.RequestHeader = http.Header{
		"Authorization": []string{"Bearer abc123"},
	}
	rp.Transport = &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}

	rp.PassPath("*", "/")
	rp.PassPaths("HEAD|GET|POST", "/api/version", "/api/posts")
	rp.RewritePath("HEAD|GET|POST", "/posts", "/api/posts")

	log.Fatal(http.ListenAndServe(":8080", rp))
}

About

🔄 Efficient reverse proxy module written in Go

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published