-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenv.go
52 lines (48 loc) · 1.4 KB
/
env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"errors"
"fmt"
"github.com/joho/godotenv"
"os"
"time"
)
const (
defaultConfig = "HOST=https://api.netwatcher.io\nHOST_WS=wss://api.netwatcher.io/agent_ws\nID=\nPIN=\n"
)
// 1.2.1b5?
const VERSION = "1.69.420_beta_gamma_fortnite"
func loadConfig(configFile string) error {
fmt.Printf("NetWatcher v%s - Copyright (c) 2024-%d Shaun Agostinho\n", VERSION, time.Now().Year())
// Check if the config file exists in the local directory
_, err := os.Stat(configFile)
// If the check returns an error indicating the file doesn't exist, create it
if errors.Is(err, os.ErrNotExist) {
// Log to terminal that a new file will be created
fmt.Printf("Config file does '%s' does not exist, creating one now.\n", configFile)
// Attempt to create the config file
_, err = os.Create(configFile)
if err != nil {
return err
}
// Attempt to write the default config pattern to the config file
err = os.WriteFile(configFile, []byte(defaultConfig), 0644)
if err != nil {
return err
}
} else if err != nil {
return err
}
// Log the current production mode to console
if os.Getenv("ENVIRONMENT") == "PRODUCTION" {
fmt.Printf("Running in PRODUCTION mode.\n")
} else {
fmt.Printf("Running in DEVELOPMENT mode.\n" /*"\u001B[1;33m", "\033[m\n"*/)
}
// Attempt to load the config file
err = godotenv.Load(configFile)
if err != nil {
return err
}
// Return normally
return nil
}