gatewayflowcontroller

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 12 Imported by: 0

README

RSS3 Gateway Flow Controller

About

This is a Traefik plugin, which controls the inbound traffic, useful for billing related requirements.

We use this with the Gateway.

Or you can also develop your own billing backend.

Questions

Why vendor dependencies

According to traefik plugin demo's readme,

Plugin dependencies must be vendored for each plugin. Vendored packages should be included in the plugin's GitHub repository. (Go modules are not supported.)

So we have to push the vendor directory.

What if my test fails

The test sometimes fails for unknown reasons (maybe connective / timing issues between this plugin and other components?). If you think your code is fine, just re-run the test a few more times, it will eventually be Success.

If it keeps failing... Maybe let's take a closer look at those new code?

I mean, only the Test. If the Lint fails, it fails.

What is the connector

Traefik doesn't like package unsafe (which has been widely used in many dependencies), so we have to split a dedicated connector to call them, contact with our plugin through rpc .

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIP

func GetIP(req *http.Request) string

func New

func New(_ context.Context, next http.Handler, config *Config, name string) (http.Handler, error)

New created a new plugin.

Types

type Config

type Config struct {
	// Request related
	KeyHeader string `json:"key_header,omitempty"`

	// Connector
	ConnectorRPC string `json:"connector_rpc,omitempty"`

	// Rate Limit
	MaxSources int           `json:"max_sources,omitempty"`
	Average    int64         `json:"average,omitempty"`
	Period     time.Duration `json:"period,omitempty"`
	Burst      int64         `json:"burst,omitempty"`
}

Config the plugin configuration.

func CreateConfig

func CreateConfig() *Config

CreateConfig creates the default plugin configuration.

type Core

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

func (*Core) ServeHTTP

func (fc *Core) ServeHTTP(rw http.ResponseWriter, req *http.Request)

The Core processor

type FlowController

type FlowController struct {
	Core
	// contains filtered or unexported fields
}

FlowController : a FlowController plugin.

func (*FlowController) ServeHTTP

func (fc *FlowController) ServeHTTP(rw http.ResponseWriter, req *http.Request)

The Full processor

func (*FlowController) Stop

func (fc *FlowController) Stop()

Stop will not be called, it's just a resource release reminder

type RateLimiter

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

func NewRateLimiter

func NewRateLimiter(maxSources int, average int64, period time.Duration, burst int64) (*RateLimiter, error)

func (*RateLimiter) RateLimit

func (rl *RateLimiter) RateLimit(rw http.ResponseWriter, req *http.Request, account *string) bool

type ResponseWriterProxy

type ResponseWriterProxy struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewResponseWriterProxy

func NewResponseWriterProxy(rw http.ResponseWriter) *ResponseWriterProxy

func (*ResponseWriterProxy) StatusCode

func (rwp *ResponseWriterProxy) StatusCode() int

func (*ResponseWriterProxy) WriteHeader

func (rwp *ResponseWriterProxy) WriteHeader(statusCode int)

Directories

Path Synopsis
main command
holster
clock
Package clock provides the same functions as the system package time.
Package clock provides the same functions as the system package time.

Jump to

Keyboard shortcuts

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