diff --git a/abstractions/init.go b/abstractions/init.go index cad9841..4a5f149 100644 --- a/abstractions/init.go +++ b/abstractions/init.go @@ -1,11 +1,26 @@ package abstractions import ( - "github.com/Akilan1999/p2p-rendering-computation/config/generate" + "github.com/Akilan1999/p2p-rendering-computation/config/generate" + "github.com/Akilan1999/p2p-rendering-computation/server" + "github.com/gin-gonic/gin" ) -func Init(name string) { - // set the config file with default paths - generate.SetDefaults(name) - +// Init Initialises p2prc +func Init(name string) (err error) { + // set the config file with default paths + err = generate.SetDefaults(name, false) + if err != nil { + return + } + return +} + +// Start p2prc in a server mode +func Start() (*gin.Engine, error) { + engine, err := server.Server() + if err != nil { + return nil, err + } + return engine, nil } diff --git a/config/config_test.go b/config/config_test.go index af5f850..811d666 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "github.com/Akilan1999/p2p-rendering-computation/config/generate" "os" "testing" ) @@ -14,14 +15,14 @@ func TestConfigInit(t *testing.T) { } func TestSetDefaults(t *testing.T) { - err := SetDefaults() + err := generate.SetDefaults("") if err != nil { t.Error(err) } } func TestGetCurrentPath(t *testing.T) { - path, err := GetCurrentPath() + path, err := generate.GetCurrentPath() if err != nil { fmt.Println(err) t.Error(err) @@ -30,7 +31,7 @@ func TestGetCurrentPath(t *testing.T) { } func TestGetPathP2PRC(t *testing.T) { - path, err := GetPathP2PRC() + path, err := GetPathP2PRC("") if err != nil { fmt.Println(err) t.Error(err) @@ -54,7 +55,7 @@ func TestSetEnvName(t *testing.T) { } // Checks if the output for the default read is "lol" - path, err := GetPathP2PRC() + path, err := GetPathP2PRC("") if err != nil { fmt.Println(err) t.Error(err) diff --git a/config/generate/generate.go b/config/generate/generate.go index f4b7415..bf64b87 100644 --- a/config/generate/generate.go +++ b/config/generate/generate.go @@ -37,7 +37,7 @@ func GetCurrentPath() (string, error) { // SetDefaults This function to be called only during a // make install -func SetDefaults(envName string) error { +func SetDefaults(envName string, forceDefault bool) error { //Setting current directory to default path defaultPath, err := GetCurrentPath() if err != nil { @@ -93,7 +93,7 @@ func SetDefaults(envName string) error { //Paths to search for config file configPaths = append(configPaths, defaultPath) - if fileExists(defaultPath + "config.json") { + if fileExists(defaultPath+"config.json") && forceDefault { err := os.Remove(defaultPath + "config.json") if err != nil { return err