-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added charm logger and fixed the .env reader
- Loading branch information
1 parent
ec5a12a
commit 0de4020
Showing
9 changed files
with
95 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,37 @@ | ||
package config | ||
|
||
import ( | ||
"log" | ||
"net/url" | ||
"os" | ||
|
||
log "github.com/charmbracelet/log" | ||
"github.com/joho/godotenv" | ||
) | ||
|
||
func GenerateLoginURLValuesFromENV(csrfToken string) (loginData url.Values, err error) { | ||
loginData = url.Values{ | ||
"user": {GetUsernameFromENV()}, | ||
"password": {GetPasswordFromENV()}, | ||
"_csrf": {csrfToken}, | ||
} | ||
if loginData.Get("user") == "" || loginData.Get("password") == "" { | ||
return loginData, err | ||
|
||
func init() { | ||
if err := godotenv.Load(); err != nil { | ||
log.Fatal("No .env file found") | ||
} | ||
return loginData, nil | ||
} | ||
|
||
func GetUsernameFromENV() (username string) { | ||
err := godotenv.Load() | ||
if err != nil { | ||
log.Fatal("Error loading .env file") | ||
} | ||
return os.Getenv("USERNAME") | ||
func GetIDFromENV() string { | ||
return os.Getenv("ID") | ||
} | ||
|
||
func GetPasswordFromENV() string { | ||
err := godotenv.Load() | ||
if err != nil { | ||
log.Fatal("Error loading .env file") | ||
} | ||
return os.Getenv("PASSWORD") | ||
} | ||
|
||
func SetUsernameInENV(username string) { | ||
err := godotenv.Load() | ||
if err != nil { | ||
log.Fatal("Error loading .env file") | ||
} | ||
os.Setenv("USERNAME", username) | ||
} | ||
|
||
func SetPasswordInENV(password string) { | ||
err := godotenv.Load() | ||
if err != nil { | ||
log.Fatal("Error loading .env file") | ||
} | ||
os.Setenv("PASSWORD", password) | ||
} | ||
|
||
func GenerateENVFile() { | ||
f, err := os.Create(".env") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer f.Close() | ||
|
||
_, err = f.WriteString("USERNAME=\nPASSWORD=") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func DoesENVFileExist() bool { | ||
if _, err := os.Stat(".env"); os.IsNotExist(err) { | ||
return false | ||
func GenerateLoginURLValuesFromENV(csrfToken string) (loginData url.Values, err error) { | ||
loginData = url.Values{ | ||
"user": {GetIDFromENV()}, | ||
"password": {GetPasswordFromENV()}, | ||
"_csrf": {csrfToken}, | ||
} | ||
return true | ||
} | ||
log.Debug("Login Data", "loginData", loginData) | ||
if loginData.Get("user") == "" || loginData.Get("password") == "" { | ||
return loginData, err | ||
|
||
func IsENVFileEmpty() bool { | ||
if GetUsernameFromENV() == "" || GetPasswordFromENV() == "" { | ||
return true | ||
} | ||
return false | ||
return loginData, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.