basic server config setup, starting to setup echo routes

This commit is contained in:
2020-06-06 17:24:23 -04:00
parent 4104193be3
commit 23dd5090e3
7 changed files with 102 additions and 31 deletions

View File

@@ -2,44 +2,51 @@ package main
import (
"fmt"
"log"
"os"
"github.com/deranjer/gvc/server/engine"
serverconfig "github.com/deranjer/gvc/server/serverconfig"
"github.com/deranjer/store"
"github.com/labstack/echo"
"github.com/labstack/gommon/log"
)
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() {
// Initialize a new server struct and config struct
var server GVCServer
var err error
var configPath string
var conf serverconfig.GvcServerConfig
configPath, err := serverconfig.FindConfig() // TODO: maybe make the findconfig a func of the struct?
configPath, err = serverconfig.FindConfig()
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,
RepoRootPath: "repos", //default repos directory will be cwd\repos
}
configPath = serverconfig.DefaultConfigPath // set the root path for our config so we can save that back to TOML
err = store.Save(serverconfig.DefaultConfigPath, &conf) // Save our new default config back to TOML so it can be read in
if err != nil {
log.Fatalf("unable to save config to toml file: %s", err)
}
}
server.configPath = configPath // set the root path for our config
err = store.Load(configPath, &conf)
err = store.Load(configPath, &conf) // existing conf was found or default conf created, so reading it in
if err != nil {
fmt.Printf("Error loading server config file into struct, please fix config, panic! \n%s", err)
os.Exit(0)
log.Fatalf("Error loading server config file into struct, please fix config, panic! \n%s", err)
}
server.config = conf // Write the conf to our server struct
err = serverconfig.ValidateConfig(&conf, configPath, version) // now that our config has been loaded, lets make sure it is valid
if err != nil {
log.Fatalf("unable to validate config, exiting: %s", err)
}
// Setup a new server instance
var server engine.GVCServer
server.Config = conf
log.Info("Logger starting...")
// Setup the web server
e := echo.New()
//Start the routes
//server.Echo.GET("/info")
}