more server work on structs and config

This commit is contained in:
2020-06-06 09:49:29 -04:00
parent b015680962
commit 4104193be3
3 changed files with 105 additions and 76 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"fmt"
"log"
"os"
serverconfig "github.com/deranjer/gvc/server/serverconfig"
@@ -10,32 +11,35 @@ import (
var version = "0.1"
// GVCServer contains all the information needed for our server so we can pass it around as needed
type GVCServer struct {
configPath string
config serverconfig.GvcServerConfig
}
func main() {
configPath, err := findConfig()
if err != nil {
fmt.Printf("Unable to find config file: %s", err)
}
// Initialize a new server struct and config struct
var server GVCServer
var conf serverconfig.GvcServerConfig
configPath, err := serverconfig.FindConfig() // TODO: maybe make the findconfig a func of the struct?
if err != nil {
fmt.Printf("Unable to find config file: %s\n", err)
fmt.Println("Since no config found, creating a default config to use...")
pwd, err := os.Getwd()
if err != nil {
log.Fatal("unable to get current working dir, exiting")
}
conf = serverconfig.GvcServerConfig{
Version: "0.1",
Port: 80,
RepoRootPath: pwd,
}
}
server.configPath = configPath // set the root path for our config
err = store.Load(configPath, &conf)
if err != nil {
fmt.Printf("Error loading server config file into struct, please fix config, panic! \n%s", err)
os.Exit(0)
}
}
func findConfig() (string, error) {
configFile, err := os.Stat("serverConfig.toml")
if err != nil {
configFile, err := os.Stat("config" + os.PathListSeparator + "serverConfig.toml")
if err != nil {
return "", err
}
if !configFile.IsDir() {
return fmt.Sprintf("config" + os.PathListSeparator + "serverConfig.toml"), nil
}
return "", fmt.Sprintf()
}
if !configFile.IsDir() {
return "serverConfig.toml", nil
}
server.config = conf // Write the conf to our server struct
}