added base abstraction functions

This commit is contained in:
2023-02-22 03:15:49 +00:00
parent 4dac4234ad
commit 60500620db
3 changed files with 27 additions and 11 deletions

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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