Skip to content

Commit

Permalink
move receiveProxyProtocol to config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
lhridder committed Jul 12, 2022
1 parent 2f63421 commit a39a96b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ fork from [haveachin/infrared](https://github.com/haveachin/infrared)

`-config-path` specifies the path to all your server configs [default: `"./configs/"`]

`-receive-proxy-protocol` if Infrared should be able to receive proxy protocol [default: `false`]

### Example Usage

`./infrared -config-path="." -receive-proxy-protocol=true`
`./infrared -config-path="."`

## Global config.json
### Example/Default
```json
{
"receiveProxyProtocol": false,
"prometheusEnabled": false,
"prometheusBind": ":9100",
"apiEnabled": false,
Expand All @@ -57,6 +56,7 @@ fork from [haveachin/infrared](https://github.com/haveachin/infrared)
```
Values can be left out if they don't deviate from the default, a config.json with just `{}` is still required for startup.
### Fields
- `receiveProxyProtocol` whether to allow for inbound proxyProtocol connections.
- `prometheusEnabled` whether to enable to builtin prometheus exporter or not.
- `prometheusBind` on what port/address to have the prometheus exporter listen on.
- `apiEnabled` if the json http api should be enabled.
Expand Down
15 changes: 5 additions & 10 deletions cmd/infrared/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ import (
)

const (
envPrefix = "INFRARED_"
envConfigPath = envPrefix + "CONFIG_PATH"
envReceiveProxyProtocol = envPrefix + "RECEIVE_PROXY_PROTOCOL"
envPrefix = "INFRARED_"
envConfigPath = envPrefix + "CONFIG_PATH"
)

const (
clfConfigPath = "config-path"
clfReceiveProxyProtocol = "receive-proxy-protocol"
clfConfigPath = "config-path"
)

var (
configPath = "./configs"
receiveProxyProtocol = false
configPath = "./configs"
)

func envBool(name string, value bool) bool {
Expand Down Expand Up @@ -50,12 +47,10 @@ func envString(name string, value string) string {

func initEnv() {
configPath = envString(envConfigPath, configPath)
receiveProxyProtocol = envBool(envReceiveProxyProtocol, receiveProxyProtocol)
}

func initFlags() {
flag.StringVar(&configPath, clfConfigPath, configPath, "path of all proxy configs")
flag.BoolVar(&receiveProxyProtocol, clfReceiveProxyProtocol, receiveProxyProtocol, "should accept proxy protocol")
flag.Parse()
}

Expand Down Expand Up @@ -95,7 +90,7 @@ func main() {
}
}()

gateway := infrared.Gateway{ReceiveProxyProtocol: receiveProxyProtocol}
gateway := infrared.Gateway{ReceiveProxyProtocol: infrared.Config.ReceiveProxyProtocol}
go func() {
for {
cfg, ok := <-outCfgs
Expand Down
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type ProxyConfig struct {
}

type GlobalConfig struct {
ReceiveProxyProtocol bool `json:"receiveProxyProtocol"`
PrometheusEnabled bool `json:"prometheusEnabled"`
PrometheusBind string `json:"prometheusBind"`
ApiEnabled bool `json:"apiEnabled"`
Expand All @@ -64,6 +65,7 @@ type GlobalConfig struct {
var Config GlobalConfig

var DefaultConfig = GlobalConfig{
ReceiveProxyProtocol: false,
PrometheusEnabled: false,
PrometheusBind: ":9100",
ApiEnabled: false,
Expand Down

0 comments on commit a39a96b

Please sign in to comment.