trying to sift through the garbage

main
KeeganForelight 2 years ago
parent 86b2d69c26
commit 6a9775facc

@ -21,10 +21,16 @@ type coordinator interface {
Start() Start()
} }
// NewCoordinator creates a new coordinator that runs on the central server
// The coordinator is given an error channel to feed errors back to the main process should any arise
// The zero value for a new coordinator is ready to start
func NewCoordinator(ch chan error) coordinator { func NewCoordinator(ch chan error) coordinator {
return server.NewCentralCoordinator(ch) return server.NewCentralCoordinator(ch)
} }
// LoadConfig loads a given config based on a string lookup
// Used to load the associated settings for a coordinator such as port and IP address as well as database settings
// LoadConfig expects the returned config to satisfy the interface
func LoadConfig(fname string) Config { func LoadConfig(fname string) Config {
if err := config.Load(fname); err != nil { if err := config.Load(fname); err != nil {
panic(err) panic(err)
@ -32,6 +38,7 @@ func LoadConfig(fname string) Config {
return config.LoadConfig() return config.LoadConfig()
} }
// Basic functions expected to be provided by the config structure
type Config interface { type Config interface {
UpdatePort(string, int) error UpdatePort(string, int) error
Store() error Store() error
@ -49,6 +56,8 @@ func main() {
errCh := make(chan error) errCh := make(chan error)
// checking env // checking env
envVars := os.Environ() envVars := os.Environ()
// I can put this is a seperate func
for _, envString := range envVars { for _, envString := range envVars {
// looping over set ports // looping over set ports
initSplt := strings.Split(envString, "=") initSplt := strings.Split(envString, "=")

@ -2,6 +2,13 @@ package config
// def.go serves as a central place to view/edit config structs and device manager map // def.go serves as a central place to view/edit config structs and device manager map
/*
Notes:
- I think that this is scuffed as all hell and I can probably vastly improve this.
- First order of buisness is to rework these definitons to even make sense
- What does the server ACTUALLY need to know and vice versa for a reactor
*/
import ( import (
"sync" "sync"
) )
@ -10,8 +17,9 @@ import (
type ServerConf struct { type ServerConf struct {
// Structure to demarshall into // Structure to demarshall into
Server ServerConfig `mapstructure:"server"` Server ServerConfig `mapstructure:"server"`
Reactors map[string]ReactorConfig `mapstructure:"reactors"` // I think this is unnessecary, who the hell cares?
//Reactors map[string]ReactorConfig `mapstructure:"reactors"`
sync.RWMutex sync.RWMutex
} }
@ -28,8 +36,9 @@ type ServerConfig struct {
type ReactorConf struct { type ReactorConf struct {
// Structure to demarshall to // Structure to demarshall to
Reactor ReactorConfig `mapstructure:"reactor"` Reactor ReactorConfig `mapstructure:"reactor"`
Devices map[int]DeviceConfig `mapstructure:"devices"` // I think this is also unnessecary, again what does it matter?
// Devices map[int]DeviceConfig `mapstructure:"devices"`
sync.RWMutex sync.RWMutex
} }

@ -20,7 +20,8 @@ import (
func NewConfig(name string) (Config, error) { func NewConfig(name string) (Config, error) {
// returns a Config Structure of assocaited name // returns a Config Structure of assocaited name
return return C, Load(name)
}
type ConfigStruct interface { type ConfigStruct interface {
// structure to do demarshall config into // structure to do demarshall config into

Loading…
Cancel
Save