pyproxy

package
v0.0.0-...-efe69f1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package pyproxy facilities migrating traffic from Python to Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy can proxy a portion of requests to Python.

func NewProxy

func NewProxy(cfg *cfg.Provider, pythonURL string) *Proxy

NewProxy sets up a proxy that send a portion of traffic to the Python host.

Requests that hit the Go server are either handled by it or get proxied to the Python server, based on `traffic_migration` table in settings.cfg.

func (*Proxy) DefaultOverride

func (m *Proxy) DefaultOverride(route string, rw http.ResponseWriter, req *http.Request) bool

DefaultOverride implements the default routing rule.

It routes the request based on "X-Route-To" header (if present) or randomly with a configured probability (if the headers is absent).

Returns true of the request was routed to Python and was already processed. Returns false if the request should be processed by Go.

func (*Proxy) PickRouteBasedOnHeaders

func (m *Proxy) PickRouteBasedOnHeaders(ctx context.Context, req *http.Request) string

PickRouteBasedOnHeaders picks a backend based on the request headers.

Returns either "go", "py" or "" (if headers indicate no preference). Logs the choice.

func (*Proxy) RandomizedOverride

func (m *Proxy) RandomizedOverride(ctx context.Context, route string, rw http.ResponseWriter, req *http.Request) bool

RandomizedOverride routes the request either to Python or Go based only on a random number generator (ignoring any headers).

Returns true of the request was routed to Python and was already processed. Returns false if the request should be processed by Go.

func (*Proxy) RouteToPython

func (m *Proxy) RouteToPython(rw http.ResponseWriter, req *http.Request)

RouteToPython sends the request to the Python server for handling.

Jump to

Keyboard shortcuts

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