General engine improvements (#437)

* Add exchange manager to engine

* Several improvements for engine and friends

1) New file.Exists func
2) gRPC TLS cert expiration date check and regeneration
3) New donation var for use across the codebase
4) Use Go log package until the logger is initialised

* Add cert tests and create dir tree if it doesn't exist for file.Write

* Link up donation address to documentation tool plus minor adjustments

* Fix remaining donation addrs

* Move non-needed reload exchange funcs

* Revert accidental config_example.json changes 🕯️

* Use go logger for logging until the logger has initiliased, otherwise no output will be seen

* Link up portfolio delay val and other fixes

* Run go mod tidy after dependabot PR

* Address nitterinos
This commit is contained in:
Adrian Gallagher
2020-02-06 12:32:01 +11:00
committed by GitHub
parent 2e6ff1c398
commit b949388994
186 changed files with 922 additions and 604 deletions

View File

@@ -54,4 +54,4 @@ When submitting a PR, please abide by our coding guidelines:
If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:
***1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB***
***bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc***

View File

@@ -63,5 +63,5 @@ When submitting a PR, please abide by our coding guidelines:
If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:
***1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB***
***bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc***

View File

@@ -5,12 +5,19 @@ import (
"io"
"io/ioutil"
"os"
"path/filepath"
)
// Write writes selected data to a file or returns an error if it fails. This
// func also ensures that all files are set to this permission (only rw access
// for the running user and the group the user is a member of)
func Write(file string, data []byte) error {
basePath := filepath.Dir(file)
if !Exists(basePath) {
if err := os.MkdirAll(basePath, 0770); err != nil {
return err
}
}
return ioutil.WriteFile(file, data, 0770)
}
@@ -45,3 +52,9 @@ func Move(sourcePath, destPath string) error {
return os.Remove(sourcePath)
}
// Exists returns whether or not a file or path exists
func Exists(name string) bool {
_, err := os.Stat(name)
return !os.IsNotExist(err)
}

View File

@@ -26,7 +26,8 @@ func TestWrite(t *testing.T) {
}
var tests []testTable
testFile := filepath.Join(os.TempDir(), "gcttest.txt")
tempDir := filepath.Join(os.TempDir(), "gct-temp")
testFile := filepath.Join(tempDir, "gcttest.txt")
switch runtime.GOOS {
case "windows":
tests = []testTable{
@@ -46,6 +47,10 @@ func TestWrite(t *testing.T) {
t.Errorf("Test %d failed, unexpected err %s\n", x, err)
}
}
if err := os.RemoveAll(tempDir); err != nil {
t.Errorf("unable to remove temp test dir %s, manual deletion required", tempDir)
}
}
func TestMove(t *testing.T) {
@@ -104,3 +109,19 @@ func TestMove(t *testing.T) {
}
}
}
func TestExists(t *testing.T) {
if e := Exists("non-existent"); e {
t.Error("non-existent file should not exist")
}
tmpFile := filepath.Join(os.TempDir(), "gct-test.txt")
if err := ioutil.WriteFile(tmpFile, []byte("hello world"), os.ModeAppend); err != nil {
t.Fatal(err)
}
if e := Exists(tmpFile); !e {
t.Error("file should exist")
}
if err := os.Remove(tmpFile); err != nil {
t.Errorf("unable to remove %s, manual deletion is required", tmpFile)
}
}