internal

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB = 1024
	MB = 1024 * KB

	ENV_PREFIX = "THRUSTER_"
)

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(options HandlerOptions) http.Handler

func NewProxyHandler

func NewProxyHandler(badGatewayPage string, forwardHeaders bool) http.Handler

func NewStashingWriter

func NewStashingWriter(limit int, dest io.Writer) *stashingWriter

func ProxyErrorHandler

func ProxyErrorHandler(badGatewayPage string) func(w http.ResponseWriter, r *http.Request, err error)

func Shutdown added in v0.0.4

func Shutdown() int

Types

type Cache

type Cache interface {
	Get(key CacheKey) ([]byte, bool)
	Set(key CacheKey, value []byte, expiresAt time.Time)
}

type CacheHandler

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

func NewCacheHandler

func NewCacheHandler(cache Cache, maxBodySize int, next http.Handler) *CacheHandler

func (*CacheHandler) ServeHTTP

func (h *CacheHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type CacheKey

type CacheKey uint64

type CacheableResponse

type CacheableResponse struct {
	StatusCode    int
	HttpHeader    http.Header
	Body          []byte
	VariantHeader http.Header
	// contains filtered or unexported fields
}

func CacheableResponseFromBuffer

func CacheableResponseFromBuffer(b []byte) (CacheableResponse, error)

func NewCacheableResponse

func NewCacheableResponse(w http.ResponseWriter, maxBodyLength int) *CacheableResponse

func (*CacheableResponse) CacheStatus

func (c *CacheableResponse) CacheStatus() (bool, time.Time)

func (*CacheableResponse) Header

func (c *CacheableResponse) Header() http.Header

func (*CacheableResponse) ToBuffer

func (c *CacheableResponse) ToBuffer() ([]byte, error)

func (*CacheableResponse) Write

func (c *CacheableResponse) Write(bytes []byte) (int, error)

func (*CacheableResponse) WriteCachedResponse

func (c *CacheableResponse) WriteCachedResponse(w http.ResponseWriter, r *http.Request)

func (*CacheableResponse) WriteHeader

func (c *CacheableResponse) WriteHeader(statusCode int)

type Config

type Config struct {
	TargetPort      int      `yaml:"target_port"`
	UpstreamCommand string   `yaml:"upstream_command"`
	UpstreamArgs    []string `yaml:"upstream_args"`

	CacheSizeBytes        int  `yaml:"cache_size_bytes"`
	MaxCacheItemSizeBytes int  `yaml:"max_cache_item_size_bytes"`
	XSendfileEnabled      bool `yaml:"x_sendfile_enabled"`
	MaxRequestBody        int  `yaml:"max_request_body"`

	BadGatewayPage string `yaml:"bad_gateway_page"`

	HttpPort         int           `yaml:"http_port"`
	HttpIdleTimeout  time.Duration `yaml:"http_idle_timeout"`
	HttpReadTimeout  time.Duration `yaml:"http_read_timeout"`
	HttpWriteTimeout time.Duration `yaml:"http_write_timeout"`

	HealthCheckPath string `yaml:"health_check_path"`

	LogLevel slog.Level `yaml:"log_level"`
}

func NewConfig

func NewConfig() (*Config, error)

type GetCurrentTime

type GetCurrentTime func() time.Time

type HandlerOptions

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

type LoggingMiddleware

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

func NewLoggingMiddleware

func NewLoggingMiddleware(logger *slog.Logger, next http.Handler) *LoggingMiddleware

func (*LoggingMiddleware) ServeHTTP

func (h *LoggingMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

type MemoryCache

type MemoryCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMemoryCache

func NewMemoryCache(capacity, maxItemSize int) *MemoryCache

func (*MemoryCache) Get

func (c *MemoryCache) Get(key CacheKey) ([]byte, bool)

func (*MemoryCache) Set

func (c *MemoryCache) Set(key CacheKey, value []byte, expiresAt time.Time)

type MemoryCacheEntry

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

type MemoryCacheEntryMap

type MemoryCacheEntryMap map[CacheKey]*MemoryCacheEntry

type MemoryCacheKeyList

type MemoryCacheKeyList []CacheKey

type Monitor added in v0.0.4

type Monitor struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMonitor added in v0.0.4

func NewMonitor(route *Route, config *Config, next http.Handler) *Monitor

func (*Monitor) ServeHTTP added in v0.0.4

func (m *Monitor) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Route added in v0.0.4

type Route struct {
	Name     string `yaml:"name"`
	Endpoint string `yaml:"endpoint"`

	Database string `yaml:"database"`
	Region   string `yaml:"region"`
	Instance string `yaml:"instance"`

	Monitor *Monitor
}

func Routes added in v0.0.4

func Routes() []Route

type Router added in v0.0.4

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

func NewRouter added in v0.0.4

func NewRouter(config *Config, next http.Handler) *Router

func (*Router) ServeHTTP added in v0.0.4

func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SendfileHandler

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

func NewSendfileHandler

func NewSendfileHandler(enabled bool, next http.Handler) *SendfileHandler

func (*SendfileHandler) ServeHTTP

func (h *SendfileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Server

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

func NewServer

func NewServer(config *Config) *Server

func (*Server) Start

func (s *Server) Start()

func (*Server) Stop

func (s *Server) Stop()

type Service

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

func NewService

func NewService(config *Config) *Service

func (*Service) HealthCheck added in v0.0.4

func (s *Service) HealthCheck(endpoint string) error

func (*Service) Start added in v0.0.4

func (s *Service) Start(route *Route) error

func (*Service) Stop added in v0.0.4

func (s *Service) Stop() int

type Settings added in v0.0.4

type Settings struct {
	Server *Config `yaml:"server"`
	Routes []Route `yaml:"routes"`
}

type UpstreamProcess

type UpstreamProcess struct {
	Started chan struct{}
	// contains filtered or unexported fields
}

func NewUpstreamProcess

func NewUpstreamProcess(name string, arg ...string) *UpstreamProcess

func (*UpstreamProcess) Signal

func (p *UpstreamProcess) Signal(sig os.Signal) error

func (*UpstreamProcess) Start added in v0.0.4

func (p *UpstreamProcess) Start() error

func (*UpstreamProcess) Stop added in v0.0.4

func (p *UpstreamProcess) Stop() (int, error)

type Variant

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

func NewVariant

func NewVariant(r *http.Request) *Variant

func (*Variant) CacheKey

func (v *Variant) CacheKey() CacheKey

func (*Variant) Matches

func (v *Variant) Matches(responseHeader http.Header) bool

func (*Variant) SetResponseHeader

func (v *Variant) SetResponseHeader(header http.Header)

func (*Variant) VariantHeader

func (v *Variant) VariantHeader() http.Header

Jump to

Keyboard shortcuts

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