You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.6 KiB
Go

package main
import (
_"net/http"
_ "net/http/pprof"
"strconv"
"strings"
//"flag"
//"log"
"os"
"fmt"
"FRMS/internal/pkg/logging"
"FRMS/internal/pkg/config"
"FRMS/internal/pkg/server"
)
type coordinator interface {
Start()
}
func NewCoordinator(ch chan error) coordinator {
return server.NewCentralCoordinator(ch)
}
func LoadConfig(fname string) Config {
config.Load(fname)
return config.LoadConfig()
}
type Config interface {
UpdatePort(string, int) error
}
func main() {
// lets get this bread
// go func() {
// fmt.Println(http.ListenAndServe("localhost:6060",nil))
// }()
conf := LoadConfig("server")
ch := make(chan error)
// checking env
envVars := os.Environ()
for _, envString := range envVars {
// looping over set ports
initSplt := strings.Split(envString,"=")
key := initSplt[0]
val := initSplt[1]
if strings.Contains(key,"PORT") {
// parsing out correct port to update
splt := strings.Split(key,"_") // LIS_PORT -> LIS, PORT
portName := strings.ToLower(splt[0]) // LIS -> lis
port, err := strconv.Atoi(val)
if err != nil {
panic(err)
}
if err := conf.UpdatePort(portName,port); err != nil {
panic(err)
}
}
}
//fmt.Printf("Listening on %v\n", lport)
c := NewCoordinator(ch)
go c.Start()
fmt.Println("Server Active!")
logging.Debug(logging.DStart, "CCO 01 Server started")
err := <-ch // blocking to wait for any errors and keep alive otherwise
panic(err)
}