diff options
| author | Melonai <einebeere@gmail.com> | 2021-07-25 23:56:25 +0200 |
|---|---|---|
| committer | Melonai <einebeere@gmail.com> | 2021-07-26 00:16:10 +0200 |
| commit | 309490948bea7cdfc4ba8b0b11966185fdd35aa9 (patch) | |
| tree | 70c091117225b0b5f19d4691024b739c478bd32d /config.go | |
| download | portgate-309490948bea7cdfc4ba8b0b11966185fdd35aa9.tar.zst portgate-309490948bea7cdfc4ba8b0b11966185fdd35aa9.zip | |
Proxy requests to target ports
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/config.go b/config.go new file mode 100644 index 0000000..cd315c0 --- /dev/null +++ b/config.go @@ -0,0 +1,39 @@ +package main + +import "fmt" + +// Config represents the global Portgate config. +type Config struct { + // Where Portgate will be running at. + portgatePort int + portgateHost string + + // Where the requests will be proxied to. + targetHost string + + allowedPorts []int + forbiddenPorts []int +} + +// GetConfig creates the Portgate config from outside sources such as +// the environment variables and the portgate.yml file. +func GetConfig() (Config, error) { + // TODO: Read config from environment/file + return Config{ + portgatePort: 8080, + targetHost: "localhost", + + allowedPorts: []int{80}, + forbiddenPorts: []int{}, + }, nil +} + +// PortgateAddress is the address on which Portgate will run. +func (c *Config) PortgateAddress() string { + return fmt.Sprintf("%s:%d", c.portgateHost, c.portgatePort) +} + +// TargetAddress is the address of the destination server. +func (c *Config) TargetAddress(port int) string { + return fmt.Sprintf("%s:%d", c.targetHost, port) +} |
