get cwd for .env

This commit is contained in:
SowinskiBraeden committed 2023-06-14 09:54:14 -07:00
1 parent 96a2f32523
commit 231e2420c2
2 files changed
+6 -3

No files matched your search

+1 -1
View File
@@ -17,7 +17,7 @@ A script to automatically handle the backing up of MongoDB databases and optiona
3. Setup your service on your UNIX-based OS, for example an Ubuntu Server. 3. Setup your service on your UNIX-based OS, for example an Ubuntu Server.
**i.** Build the project to a binary. **i.** Build the project to a binary.
```bash ```bash
$ go build $ go build main.go
``` ```
**ii.** Create a System Service file **ii.** Create a System Service file
```bash ```bash
+5 -2
View File
@@ -25,7 +25,7 @@ func LogToFile(message string) {
f, err := os.OpenFile("databaseBackup.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666) f, err := os.OpenFile("databaseBackup.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
Handle(err) Handle(err)
defer f.Close() defer f.Close()
log.SetOutput(f) log.SetOutput(f)
log.Println(fmt.Sprintf(" | %s", message)) log.Println(fmt.Sprintf(" | %s", message))
} }
@@ -55,8 +55,11 @@ func UploadToGithub(archiveDir string) {
} }
func main() { func main() {
path, err := os.Getwd()
Handle(err)
// Load environment variables // Load environment variables
godotenv.Load(".env") godotenv.Load(fmt.Sprintf("%s/.env", path))
var mongoURI string = os.Getenv("mongoURI") var mongoURI string = os.Getenv("mongoURI")
var database_string string = os.Getenv("databases") var database_string string = os.Getenv("databases")
var github string = os.Getenv("github") var github string = os.Getenv("github")