gondola

package module
v0.0.0-...-83cc058 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 13 Imported by: 0

README

gondola

GitHub release Go Report Card codecov GitHub license Go Reference Sourcegraph

A golang reverse proxy.

gondola

This log was created by gopherize.me

Table of contents

Features

  • Virtual host
  • Configuration file loader
  • TLS
  • Serve static files
  • Access log
  • CLI and binary distribution

Install

go get -u github.com/bmf-san/gondola

or you can download the binary from the release page.

Example

See below for how to use gondola.

Usage

Run a binary with the option.

gondola -config config.yaml

Projects

ADR

Wiki

Contribution

Issues and Pull Requests are always welcome.

We would be happy to receive your contributions.

Please review the following documents before making a contribution.

Sponsor

If you like it, I would be happy to have you sponsor it!

Github Sponsors - bmf-san

Or I would be happy to get a STAR.

It motivates me to keep up with ongoing maintenance. :D

License

Based on the MIT License.

LICENSE

Stargazers

Forkers

Author

bmf-san

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTraceID

func GetTraceID(ctx context.Context) string

GetTraceID returns a trace ID from the context.

func WithTraceID

func WithTraceID(ctx context.Context) context.Context

WithTraceID adds a trace ID to the context.

Types

type Config

type Config struct {
	Proxy     Proxy      `yaml:"proxy"`
	Upstreams []Upstream `yaml:"upstreams"`
	LogLevel  int        `yaml:"log_level"` // Debug:-4 Info:0 Warn:4 Error:8
}

Config is a struct that represents the configuration of the proxy.

func (*Config) Load

func (c *Config) Load(reader io.Reader) (*Config, error)

Load reads the configuration from a reader and returns a Config struct.

type Gondola

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

Gondola is a proxy server.

func NewGondola

func NewGondola(r io.Reader) (*Gondola, error)

NewGondola returns a new Gondola.

func (*Gondola) Run

func (g *Gondola) Run() error

TODO: Need to dynamically load a configuration file. For now, we will limit the implementation to just loading the file at startup. Run starts the proxy server.

type LogRoundTripper

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

LogRoundTripper is a RoundTripper that logs the request and response.

func NewLogRoundTripper

func NewLogRoundTripper(transport http.RoundTripper) *LogRoundTripper

NewLogRoundTripper returns a new LogRoundTripper.

func (*LogRoundTripper) RoundTrip

func (lrt *LogRoundTripper) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface. It logs the request and response.

type Logger

type Logger struct {
	*slog.Logger
}

Logger is a logger.

func NewLogger

func NewLogger(level int) *Logger

NewLogger creates a logger.

type Proxy

type Proxy struct {
	Port              string       `yaml:"port"`
	ReadHeaderTimeout int          `yaml:"read_header_timeout"`
	ShutdownTimeout   int          `yaml:"shutdown_timeout"`
	TLSCertPath       string       `yaml:"tls_cert_path"`
	TLSKeyPath        string       `yaml:"tls_key_path"`
	StaticFiles       []StaticFile `yaml:"static_files"`
}

Proxy is a struct that represents the proxy server. Port is the port that the proxy server will listen on. ShutdownTimeout is the timeout in milliseconds for the proxy server to shutdown.

func (*Proxy) IsEnableTLS

func (p *Proxy) IsEnableTLS() bool

IsEnableTLS returns true if the proxy server is configured to use TLS.

type ProxyHandler

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

ProxyHandler is a http.Handler that proxies the request.

func (*ProxyHandler) Handler

func (h *ProxyHandler) Handler(w http.ResponseWriter, r *http.Request)

Handler implements the http.Handler interface. It proxies the request.

type StaticFile

type StaticFile struct {
	Path string `yaml:"path"`
	Dir  string `yaml:"dir"`
}

StaticFile is a struct that represents a static file configuration.

type TraceIDHandler

type TraceIDHandler struct {
	slog.Handler
}

TraceIDHandler is a handler for trace ID.

func (TraceIDHandler) Handle

func (t TraceIDHandler) Handle(ctx context.Context, r slog.Record) error

Handle adds a trace ID to the record.

type Upstream

type Upstream struct {
	HostName string `yaml:"host_name"`
	Target   string `yaml:"target"`
}

Upstream is a struct that represents a backend server. HostName is the hostname that the proxy will listen for. Target is the target URL that the proxy will forward requests to.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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