added easier use of abstractions
This commit is contained in:
@@ -1,32 +1,52 @@
|
||||
package abstractions
|
||||
|
||||
import (
|
||||
"github.com/Akilan1999/p2p-rendering-computation/config"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/server"
|
||||
"github.com/gin-gonic/gin"
|
||||
Config "github.com/Akilan1999/p2p-rendering-computation/config"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/server"
|
||||
"github.com/gin-gonic/gin"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Init Initialises p2prc
|
||||
func Init(customConfig interface{}) (config *config.Config, err error) {
|
||||
// set the config file with default paths
|
||||
config, err = generate.SetDefaults("P2PRC", false, customConfig, false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
func Init(customConfig interface{}) (config *Config.Config, err error) {
|
||||
|
||||
// Get config file path
|
||||
// Checks P2PRC path initially
|
||||
// - Get PATH if environment varaible
|
||||
path, err := Config.GetPathP2PRC("P2PRC")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// check if the config file exists
|
||||
if _, err = os.Stat(path + "config.json"); err != nil {
|
||||
// Initialize with base p2prc config files
|
||||
// set the config file with default paths
|
||||
config, err = generate.SetDefaults("P2PRC", false, customConfig, false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// If the configs are available then use them over generating new ones.
|
||||
config, err = Config.ConfigInit(nil, nil)
|
||||
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
|
||||
engine, err := server.Server()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return engine, nil
|
||||
}
|
||||
|
||||
func MapPort(port string) (entireAddres string, mapPort string, err error) {
|
||||
entireAddres, mapPort, err = server.MapPort(port)
|
||||
return
|
||||
entireAddres, mapPort, err = server.MapPort(port)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -39,6 +39,12 @@ type Config struct {
|
||||
//NetworkInterfaceIPV6Index int
|
||||
}
|
||||
|
||||
// GetCurrentPath Getting P2PRC Directory from environment variable
|
||||
func GetCurrentPath() (string, error) {
|
||||
curDir := os.Getenv("PWD")
|
||||
return curDir + "/", nil
|
||||
}
|
||||
|
||||
// GetPathP2PRC Getting P2PRC Directory from environment variable
|
||||
func GetPathP2PRC(Envname string) (string, error) {
|
||||
if Envname != "" {
|
||||
@@ -49,7 +55,10 @@ func GetPathP2PRC(Envname string) (string, error) {
|
||||
}
|
||||
curDir := os.Getenv(defaultEnvName)
|
||||
if curDir == "" {
|
||||
return curDir, nil
|
||||
// if the OS env path is not found then you use
|
||||
// the current directory path.
|
||||
currentPath, _ := GetCurrentPath()
|
||||
return currentPath, nil
|
||||
}
|
||||
return curDir + "/", nil
|
||||
}
|
||||
|
||||
@@ -31,17 +31,11 @@ func SetEnvName(EnvName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetCurrentPath Getting P2PRC Directory from environment variable
|
||||
func GetCurrentPath() (string, error) {
|
||||
curDir := os.Getenv("PWD")
|
||||
return curDir + "/", nil
|
||||
}
|
||||
|
||||
// SetDefaults This function to be called only during a
|
||||
// make install
|
||||
func SetDefaults(envName string, forceDefault bool, CustomConfig interface{}, NoBoilerPlate bool, ConfigUpdate ...*config.Config) (*config.Config, error) {
|
||||
//Setting current directory to default path
|
||||
defaultPath, err := GetCurrentPath()
|
||||
defaultPath, err := config.GetCurrentPath()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/config"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"golang.org/x/crypto/ssh"
|
||||
@@ -61,7 +62,7 @@ func GenerateIPTableFile(rootNodes []p2p.IpAddress) (err error) {
|
||||
|
||||
// CreateIPTableFolderStructure Create folder structure for IPTable
|
||||
func CreateIPTableFolderStructure() (err error) {
|
||||
path, err := GetCurrentPath()
|
||||
path, err := config.GetCurrentPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -87,7 +88,7 @@ func CreateIPTableFolderStructure() (err error) {
|
||||
|
||||
// GenerateDockerFiles Generate default docker files
|
||||
func GenerateDockerFiles() (err error) {
|
||||
path, err := GetCurrentPath()
|
||||
path, err := config.GetCurrentPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -132,7 +133,7 @@ func GenerateDockerFiles() (err error) {
|
||||
|
||||
// GeneratePluginDirectory Generates plugin directory structure
|
||||
func GeneratePluginDirectory() (err error) {
|
||||
path, err := GetCurrentPath()
|
||||
path, err := config.GetCurrentPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -150,7 +151,7 @@ func GeneratePluginDirectory() (err error) {
|
||||
}
|
||||
|
||||
func GenerateClientTrackContainers() (err error) {
|
||||
path, err := GetCurrentPath()
|
||||
path, err := config.GetCurrentPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user