added the possiblility to add custom varaibles

This commit is contained in:
2021-09-17 16:44:34 +04:00
parent 5da700a9d0
commit 1ca73faaed
3 changed files with 39 additions and 3 deletions

View File

@@ -13,6 +13,7 @@ var (
configType = "json"
configFile = "config.json"
configPaths []string
defaultEnvName = "P2PRC"
)
type Config struct {
@@ -64,10 +65,20 @@ func Copy(src, dst string) error {
// GetPathP2PRC Getting P2PRC Directory from environment variable
func GetPathP2PRC()(string,error) {
curDir := os.Getenv("P2PRC")
curDir := os.Getenv(defaultEnvName)
return curDir + "/", nil
}
// SetEnvName Sets the environment name
// This is to ensure that the Path of your project is detected from
// your environment variable
// This is useful when extending the use case of P2PRC
func SetEnvName(EnvName string) error {
defaultEnvName = EnvName
// Handling error to be implemented only if needed
return nil
}
// GetCurrentPath Getting P2PRC Directory from environment variable
func GetCurrentPath()(string,error) {
curDir := os.Getenv("PWD")

View File

@@ -2,6 +2,7 @@ package config
import (
"fmt"
"os"
"testing"
)
@@ -36,3 +37,27 @@ func TestGetPathP2PRC(t *testing.T) {
}
fmt.Println(path)
}
func TestSetEnvName(t *testing.T) {
// Create an Env variable TEST with the value "lol"
err := os.Setenv("TEST", "lol")
if err != nil {
fmt.Println(err)
t.Error(err)
}
// Sets the environment variable as the default to read
// for P2PRC
err = SetEnvName("TEST")
if err != nil {
fmt.Println(err)
t.Error(err)
}
// Checks if the output for the default read is "lol"
path, err := GetPathP2PRC()
if err != nil {
fmt.Println(err)
t.Error(err)
}
fmt.Println(path)
}

View File

@@ -30,13 +30,13 @@
<li>
<b>Only for v1.0.0</b>
<br>
<b>IP Address: 172.104.44.195</b>
<!-- <b>IP Address: 172.104.44.195</b>-->
<p>Use this server to only download part of the p2p network</p>
</li>
<li>
<b>Master branch</b>
<br>
<b>IP Address: 139.162.246.221</b>
<!-- <b>IP Address: 139.162.246.221</b>-->
<p>Use this server to only download part of the p2p network</p>
</li>
</ul>