freighter

package module
v0.0.0-...-25641f1 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 10 Imported by: 0

README

Freighter

Simple Load-Balancer written in Go-lang.

Freighter is not a pre-built binary/CLI-application, instead it is a Go library which you can add to your own binary. This allows you to very easily extend its functionality and maybe even add new features which you require. Also, this helps avoid unnecessarily complicated configuration files.

Documentation: https://shardulnalegave.github.io/freighter

package main

import (
	"net/url"
	"time"

	"github.com/ShardulNalegave/freighter"
	"github.com/ShardulNalegave/freighter/pool"
	"github.com/ShardulNalegave/freighter/strategy"
)

func main() {
	srv := freighter.NewFreighter(&freighter.Options{
		URL: &url.URL{
			Host: ":5000",
		},
		EnableConsoleLogging: true,
		HealthCheckInterval:  time.Second * 5,
		Strategy:             &strategy.RoundRobin{},
		Backends: []*pool.Backend{
			pool.NewBackend(&url.URL{Host: ":8080", Scheme: "http"}, nil),
			pool.NewBackend(&url.URL{Host: ":8081", Scheme: "http"}, nil),
		},
	})

	srv.ListenAndServe()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HealthCheck

func HealthCheck(p *pool.ServerPool, interval time.Duration)

Types

type Freighter

type Freighter struct {
	URL *url.URL

	Strategy strategy.Strategy
	// contains filtered or unexported fields
}

func NewFreighter

func NewFreighter(opts *Options) *Freighter

func (*Freighter) Handle

func (f *Freighter) Handle(w http.ResponseWriter, r *http.Request)

func (*Freighter) ListenAndServe

func (f *Freighter) ListenAndServe()

type Options

type Options struct {
	URL                  *url.URL
	Strategy             strategy.Strategy
	Backends             []*pool.Backend
	HealthCheckInterval  time.Duration
	EnableConsoleLogging bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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