fix some shutdown bugs and so on
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,4 +4,4 @@ bin/
|
|||||||
data.json
|
data.json
|
||||||
*.json
|
*.json
|
||||||
config.yaml
|
config.yaml
|
||||||
|
.direnv/
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ type Config struct {
|
|||||||
Enabled bool `yaml:"enabled"`
|
Enabled bool `yaml:"enabled"`
|
||||||
Path string `yaml:"path"`
|
Path string `yaml:"path"`
|
||||||
MaxAge int `yaml:"maxAge"`
|
MaxAge int `yaml:"maxAge"`
|
||||||
MaxBackups int `yamls:"maxBackups"`
|
MaxBackups int `yaml:"maxBackups"`
|
||||||
} `yaml:"file"`
|
} `yaml:"file"`
|
||||||
} `yaml:"logging"`
|
} `yaml:"logging"`
|
||||||
Metrics struct {
|
Metrics struct {
|
||||||
|
|||||||
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1783522502,
|
||||||
|
"narHash": "sha256-iffAls3iaNTyJC2faYcUXSI+Gp02cDjYl+MygxKl2GI=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "0bb7ec54c8483066ec9d7720e780a5caa71f8612",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
30
flake.nix
Normal file
30
flake.nix
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
description = "Reverse proxy";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs =
|
||||||
|
{
|
||||||
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
flake-utils,
|
||||||
|
}:
|
||||||
|
flake-utils.lib.eachDefaultSystem (
|
||||||
|
system:
|
||||||
|
let
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
go
|
||||||
|
gopls
|
||||||
|
go-tools
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -43,6 +43,7 @@ func NewMetrics(bufferSize int, flushTimeout time.Duration, file string) *Metric
|
|||||||
c: make(chan RequestMetric, bufferSize),
|
c: make(chan RequestMetric, bufferSize),
|
||||||
ticker: time.NewTicker(flushTimeout),
|
ticker: time.NewTicker(flushTimeout),
|
||||||
file: file,
|
file: file,
|
||||||
|
stop: make(chan struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ func NewLimiter(maxRequests int, refills int, refillInterval time.Duration, clea
|
|||||||
bucketRefill: refills,
|
bucketRefill: refills,
|
||||||
rwLock: &sync.RWMutex{},
|
rwLock: &sync.RWMutex{},
|
||||||
rateChannel: make(chan string),
|
rateChannel: make(chan string),
|
||||||
|
stop: make(chan struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ func New(config *Config, client *http.Client) Router {
|
|||||||
for _, host := range config.Hosts {
|
for _, host := range config.Hosts {
|
||||||
for _, domain := range host.Domains {
|
for _, domain := range host.Domains {
|
||||||
curr := Host{host.Port, host.Remotes, host.Secure, &atomic.Uint32{}, make(map[string]*Host), host.AdditionalHeaders}
|
curr := Host{host.Port, host.Remotes, host.Secure, &atomic.Uint32{}, make(map[string]*Host), host.AdditionalHeaders}
|
||||||
m[domain] = curr
|
|
||||||
|
|
||||||
for subUrl, rewriteHost := range host.Rewrite {
|
for subUrl, rewriteHost := range host.Rewrite {
|
||||||
rewrite, ok := m[rewriteHost]
|
rewrite, ok := m[rewriteHost]
|
||||||
@@ -46,6 +45,7 @@ func New(config *Config, client *http.Client) Router {
|
|||||||
}
|
}
|
||||||
curr.Rewrites[subUrl] = &rewrite
|
curr.Rewrites[subUrl] = &rewrite
|
||||||
}
|
}
|
||||||
|
m[domain] = curr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ func rewriteRequestURL(r *http.Request, host *Host, remote string) error {
|
|||||||
r.RequestURI = ""
|
r.RequestURI = ""
|
||||||
r.URL.Scheme = remoteUrl.Scheme
|
r.URL.Scheme = remoteUrl.Scheme
|
||||||
r.URL.Host = remoteUrl.Host
|
r.URL.Host = remoteUrl.Host
|
||||||
r.Header.Set("X-Forwarded-For", r.RemoteAddr)
|
r.Header.Set("X-Forwarded-For", strings.Split(r.RemoteAddr, ":")[0])
|
||||||
r.Header.Set("Cache-Control", "no-store, no-cache, max-age=0, must-revalidate, proxy-revalidate")
|
r.Header.Set("Cache-Control", "no-store, no-cache, max-age=0, must-revalidate, proxy-revalidate")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user