65 lines
1.7 KiB
Markdown
65 lines
1.7 KiB
Markdown
# Sentinel
|
|
|
|
Sentinel is a highly-available reverse proxy that can be used to distribute traffic to multiple backends. It is designed to be simple to use and easy to configure.
|
|
|
|
## Features
|
|
|
|
- Simple to use
|
|
- Easy to configure
|
|
- Highly-available
|
|
|
|
## Installation
|
|
|
|
To install Sentinel, you can use the following command:
|
|
|
|
```
|
|
go get github.com/juls0730/sentinel
|
|
```
|
|
|
|
## Usage
|
|
|
|
all you need is a structure that holds the proxyManager structure and a function that returns a transport for the proxyManager
|
|
|
|
```go
|
|
package main
|
|
|
|
import (
|
|
"github.com/juls0730/sentinel"
|
|
"net/http"
|
|
)
|
|
|
|
func main() {
|
|
proxyManager := sentinel.NewProxyManager()
|
|
|
|
proxyManager.ListenAndServe("localhost:8080")
|
|
|
|
proxy, err := NewDeploymentProxy(socketPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
proxyManager.AddProxy("text.local", proxy)
|
|
}
|
|
|
|
type unixDialer struct {
|
|
socketPath string
|
|
}
|
|
|
|
// dialContext implements DialContext but ignored everthing and just gives you a connection to the unix socket
|
|
func (d *unixDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
|
return net.Dial("unix", d.socketPath)
|
|
}
|
|
|
|
func getTransport(target string) *http.Transport {
|
|
return &http.Transport{
|
|
DialContext: (&unixDialer{socketPath: socket}).DialContext,
|
|
MaxIdleConns: 100,
|
|
IdleConnTimeout: 90 * time.Second,
|
|
MaxIdleConnsPerHost: 100,
|
|
ForceAttemptHTTP2: false,
|
|
}
|
|
|
|
}
|
|
```
|
|
|
|
If you want more indepth examples of how to use Sentinel, you can check out [gloom](https://github.com/juls0730/gloom) which is a plugin-based web server that uses Sentinel to distribute traffic to multiple backends, or [Flux](https://github.com/juls0730/flux) which is a mini-paas that uses Sentinel to distribute traffic to project containers. |