lb

package module
v0.0.0-...-f629cec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

min-rp

Minimal Reverse Proxy with different modes implemented in Golang

Quick Setup

Check full examples at examples/ directory

rp.SetReverseProxyAndServe(
    &rp.SetReverseProxyAndServeOpts{
        Config: &rp.Config{
            ReverseProxy: rp.ReverseProxy{
                Port: "8080",
            },
            Workers: []*rp.Worker{
                {URL: "http://localhost:8081/"},
                {URL: "http://localhost:8082/"},
                {URL: "http://localhost:8083/"},
            },
            Type: ReverseProxyTypePathPrefix,
        },
    },
)

Reverse Proxy Types

  1. Path Matching - ReverseProxyTypePathPrefix
  2. Round Robin - ReverseProxyTypeRoundRobin

Bugs

Bugs or suggestions? Open an issue here.

Documentation

Index

Constants

View Source
const (
	HTTPConnTypeTCP            string           = "tcp"
	ReverseProxyTypeRoundRobin ReverseProxyType = "RoundRobin"
	ReverseProxyTypePathPrefix ReverseProxyType = "PathPrefix"
)

Variables

This section is empty.

Functions

func ReverseProxyHandler

func ReverseProxyHandler(w http.ResponseWriter, r *http.Request)

func SetReverseProxyAndServe

func SetReverseProxyAndServe(opts *SetReverseProxyAndServeOpts)

Types

type Config

type Config struct {
	ReverseProxy ReverseProxy
	Workers      []*Worker
	Type         ReverseProxyType
}

func (*Config) FindCurrentWorker

func (config *Config) FindCurrentWorker(w http.ResponseWriter, r *http.Request) *Worker

func (*Config) FindWorkerByPath

func (config *Config) FindWorkerByPath(w http.ResponseWriter, r *http.Request) *Worker

func (*Config) FindWorkerByRoundRobin

func (config *Config) FindWorkerByRoundRobin(w http.ResponseWriter, r *http.Request) *Worker

type Path

type Path string // Path represents a URL path

type ReverseProxy

type ReverseProxy struct {
	Port string
}

type ReverseProxyType

type ReverseProxyType string

type SetReverseProxyAndServeOpts

type SetReverseProxyAndServeOpts struct {
	*Config
}

type Worker

type Worker struct {
	URL   string
	Alive bool

	Paths []Path
	// contains filtered or unexported fields
}

func (*Worker) IsAlive

func (worker *Worker) IsAlive() bool

func (*Worker) SetAlive

func (worker *Worker) SetAlive(b bool)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL