Move the scripted networking to it's own file.
This commit is contained in:
parent
a6b00f4c39
commit
1d3dad77a4
37
main.go
37
main.go
|
@ -5,7 +5,6 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
|
@ -26,7 +25,6 @@ type SystemConfig struct {
|
|||
}
|
||||
|
||||
type NetworkingConfig struct {
|
||||
proxy map[int]string
|
||||
}
|
||||
|
||||
type ServiceConfig struct {
|
||||
|
@ -49,6 +47,9 @@ func main() {
|
|||
var err error
|
||||
var config Config
|
||||
|
||||
// Initialize structs for scripted configurations
|
||||
ScriptedInit()
|
||||
|
||||
// Read user config file
|
||||
{
|
||||
file, err := os.ReadFile("goolinux.json")
|
||||
|
@ -87,9 +88,6 @@ func main() {
|
|||
mergo.Merge(&config, systemConfig, mergo.WithOverride)
|
||||
}
|
||||
|
||||
// Initialize any needed maps in the config
|
||||
config.Networking.proxy = make(map[int]string)
|
||||
|
||||
// Parse user services
|
||||
for name, service := range config.Services {
|
||||
var b strings.Builder
|
||||
|
@ -145,38 +143,15 @@ func main() {
|
|||
fmt.Println("Error: No port defined for proxy to", s.Proxy)
|
||||
return
|
||||
}
|
||||
port, err := strconv.Atoi(ports[0])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Printf("Error: proxy for %s has an invalid port definition: %s\n", s.Proxy, ports)
|
||||
return
|
||||
}
|
||||
|
||||
conflict, exists := config.Networking.proxy[port]
|
||||
if exists == true {
|
||||
fmt.Println("Error: Conflicting proxy settings:")
|
||||
fmt.Printf(" %s:%s\n", conflict, port)
|
||||
fmt.Printf(" %s:%s\n", s.Proxy, port)
|
||||
}
|
||||
|
||||
config.Networking.proxy[port] = s.Proxy
|
||||
AddProxy(s.Proxy, ports[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle any special case (scripted) configs
|
||||
{
|
||||
// Expand Networking.proxy to Services.proxy.Config.scripted_proxy
|
||||
type proxy struct {
|
||||
Domain string
|
||||
Port int
|
||||
}
|
||||
var p []proxy
|
||||
for port, domain := range config.Networking.proxy {
|
||||
p = append(p, proxy{Domain: domain, Port: port})
|
||||
}
|
||||
|
||||
config.Services["proxy"].Config["scripted_proxy"] = p
|
||||
// Expand the proxy list to Services.proxy.Config.scripted_proxy
|
||||
config.Services["proxy"].Config["scripted_proxy"] = GetProxy()
|
||||
}
|
||||
|
||||
// Generate service config templates
|
||||
|
|
44
scripted.go
Normal file
44
scripted.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Proxy struct {
|
||||
Domain string
|
||||
Port int
|
||||
}
|
||||
|
||||
var proxyList map[int]string
|
||||
|
||||
func ScriptedInit() {
|
||||
proxyList = make(map[int]string)
|
||||
}
|
||||
|
||||
func GetProxy() ([]Proxy) {
|
||||
var p []Proxy
|
||||
for port, domain := range proxyList {
|
||||
p = append(p, Proxy{Domain: domain, Port: port})
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func AddProxy(domain string, port string) {
|
||||
p, err := strconv.Atoi(port)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Printf("Error: proxy for %s, port is not a number: %s\n", domain, port)
|
||||
return
|
||||
}
|
||||
|
||||
conflict, exists := proxyList[p]
|
||||
if exists == true {
|
||||
fmt.Println("Error: Conflicting proxy settings:")
|
||||
fmt.Printf(" %s:%s\n", conflict, p)
|
||||
fmt.Printf(" %s:%s\n", domain, p)
|
||||
return
|
||||
}
|
||||
|
||||
proxyList[p] = domain
|
||||
}
|
Loading…
Reference in a new issue