blob: ad1b7b82974e3a4f327021d3007b3a4d39c6cdfb (
plain) (
blame)
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
|
// Package config loads env fils into a Login struct which gets passed to the rest of the application
package config
import (
"fmt"
"log"
"os"
"github.com/joho/godotenv"
)
type Login struct {
User string
Pass string
IP string
Port string
Name string
}
func CreateEnvFile() error {
err := os.WriteFile(".env", nil, 0o666)
if err != nil {
return err
}
err = godotenv.Load(".env")
if err != nil {
log.Fatal("Error loading .env file")
}
os.Setenv("DATABASE_USER", "nasr")
os.Setenv("DATABASE_PASSWORD", "root")
os.Setenv("DATABASE_IP", "127.0.0.1")
os.Setenv("DATABASE_PORT", "3306")
os.Setenv("DATABASE_NAME", "synf")
return nil
}
func (L *Login) LoadCredentials() {
err := godotenv.Load(".env")
if err != nil {
fmt.Println("error in loading credentials")
}
L.User = os.Getenv("DATABASE_USER")
L.Pass = os.Getenv("DATABASE_PASSWORD")
L.IP = os.Getenv("DATABASE_IP")
L.Port = os.Getenv("DATABASE_PORT")
L.Name = os.Getenv("DATABASE_NAME")
}
|