59 lines
2.1 KiB
Go
59 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"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"
|
|
|
|
func main() {
|
|
// Initialize a new server struct and config struct
|
|
var err error
|
|
var configPath string
|
|
var conf serverconfig.GvcServerConfig
|
|
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...")
|
|
conf = serverconfig.GvcServerConfig{
|
|
Version: "0.1",
|
|
Port: 80,
|
|
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)
|
|
}
|
|
}
|
|
err = store.Load(configPath, &conf) // existing conf was found or default conf created, so reading it in
|
|
if err != nil {
|
|
log.Fatalf("Error loading server config file into struct, please fix config, panic! \n%s", err)
|
|
}
|
|
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()
|
|
server.Echo = e
|
|
//Start the routes
|
|
//e.GET("/hello", server.Hello)
|
|
e.GET("/:repo/info/", server.GetInfo)
|
|
e.GET("/:repo/lock/:type/:name", server.LockFile)
|
|
e.GET("/:repo/refresh", server.Refresh)
|
|
e.GET("/:repo/revert/:hash", server.Revert) // TODO: Might not need this, just add extra args to pull?
|
|
e.GET("/:repo/pull/:branch", server.Pull)
|
|
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%d", server.Config.BindIP, server.Config.Port)))
|
|
}
|