Automatically generate the .env file if it is not there
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
root = "."
|
||||||
|
testdata_dir = "testdata"
|
||||||
|
tmp_dir = "tmp"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
args_bin = []
|
||||||
|
bin = "./tmp/main"
|
||||||
|
cmd = "time go build -gcflags=\"all=-l\" -ldflags=\"-w -s\" -o ./tmp/main main.go"
|
||||||
|
delay = 1000
|
||||||
|
exclude_dir = ["assets", "tmp", "vendor", "testdata", "cdk", "dist", "db", "static"]
|
||||||
|
exclude_file = []
|
||||||
|
exclude_regex = ["_test.go"]
|
||||||
|
exclude_unchanged = false
|
||||||
|
follow_symlink = false
|
||||||
|
full_bin = ""
|
||||||
|
include_dir = []
|
||||||
|
include_ext = ["go", "tpl", "tmpl", "html", "gohtml", "css", "js"]
|
||||||
|
include_file = []
|
||||||
|
kill_delay = "0s"
|
||||||
|
log = "build-errors.log"
|
||||||
|
poll = false
|
||||||
|
poll_interval = 0
|
||||||
|
post_cmd = []
|
||||||
|
pre_cmd = []
|
||||||
|
rerun = false
|
||||||
|
rerun_delay = 500
|
||||||
|
send_interrupt = false
|
||||||
|
stop_on_error = false
|
||||||
|
|
||||||
|
[color]
|
||||||
|
app = ""
|
||||||
|
build = "yellow"
|
||||||
|
main = "magenta"
|
||||||
|
runner = "green"
|
||||||
|
watcher = "cyan"
|
||||||
|
|
||||||
|
[log]
|
||||||
|
main_only = false
|
||||||
|
time = false
|
||||||
|
|
||||||
|
[misc]
|
||||||
|
clean_on_exit = false
|
||||||
|
|
||||||
|
[proxy]
|
||||||
|
app_port = 8090
|
||||||
|
enabled = true
|
||||||
|
proxy_port = 8091
|
||||||
|
|
||||||
|
[screen]
|
||||||
|
clear_on_rebuild = false
|
||||||
|
keep_scroll = true
|
||||||
Vendored
+8
-13
@@ -10,7 +10,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
EnvKeyRepositoryType = "REPOSITORY_TYPE"
|
|
||||||
EnvKeyDatabaseURL = "DATABASE_URL"
|
EnvKeyDatabaseURL = "DATABASE_URL"
|
||||||
EnvKeySessionSecret = "SESSION_SECRET"
|
EnvKeySessionSecret = "SESSION_SECRET"
|
||||||
EnvKeyBaseURL = "BASE_URL"
|
EnvKeyBaseURL = "BASE_URL"
|
||||||
@@ -33,7 +32,6 @@ type Environment struct {
|
|||||||
DatabaseUrl string
|
DatabaseUrl string
|
||||||
MistralApiKey string
|
MistralApiKey string
|
||||||
IsDev bool
|
IsDev bool
|
||||||
RepositoryType string
|
|
||||||
GoogleSheetsCredPath string
|
GoogleSheetsCredPath string
|
||||||
GoogleSheetsSpreadId string
|
GoogleSheetsSpreadId string
|
||||||
GoogleSheetsSheetName string
|
GoogleSheetsSheetName string
|
||||||
@@ -54,21 +52,21 @@ type KeycloakConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func LoadEnvironment() Environment {
|
func LoadEnvironment() Environment {
|
||||||
|
if _, err := os.Stat(".env"); err != nil {
|
||||||
|
err = GenerateEnvFile("", false)
|
||||||
|
if err != nil {
|
||||||
|
Error("error generating the environment file", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogError("Error loading .env file: %v", err)
|
LogError("Error loading .env file: %v", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
// Default repository type is postgres if not specified
|
|
||||||
repoType := os.Getenv(EnvKeyRepositoryType)
|
|
||||||
if repoType == "" {
|
|
||||||
repoType = "postgres"
|
|
||||||
}
|
|
||||||
|
|
||||||
return Environment{
|
return Environment{
|
||||||
DatabaseUrl: os.Getenv(EnvKeyDatabaseURL),
|
DatabaseUrl: os.Getenv(EnvKeyDatabaseURL),
|
||||||
IsDev: os.Getenv(EnvKeyIsDev) == "true" || os.Getenv(EnvKeyIsLocal) == "true",
|
IsDev: os.Getenv(EnvKeyIsDev) == "true" || os.Getenv(EnvKeyIsLocal) == "true",
|
||||||
RepositoryType: repoType,
|
|
||||||
GoogleClientId: os.Getenv(EnvKeyGoogleClientID),
|
GoogleClientId: os.Getenv(EnvKeyGoogleClientID),
|
||||||
GoogleClientSecret: os.Getenv(EnvKeyGoogleClientSecret),
|
GoogleClientSecret: os.Getenv(EnvKeyGoogleClientSecret),
|
||||||
GoogleRedirectUrl: os.Getenv(EnvKeyGoogleRedirectURL),
|
GoogleRedirectUrl: os.Getenv(EnvKeyGoogleRedirectURL),
|
||||||
@@ -88,7 +86,6 @@ func LoadEnvironment() Environment {
|
|||||||
// without duplicating or hard-coding the list elsewhere.
|
// without duplicating or hard-coding the list elsewhere.
|
||||||
func EnvKeys() []string {
|
func EnvKeys() []string {
|
||||||
return []string{
|
return []string{
|
||||||
EnvKeyRepositoryType,
|
|
||||||
EnvKeyDatabaseURL,
|
EnvKeyDatabaseURL,
|
||||||
EnvKeySessionSecret,
|
EnvKeySessionSecret,
|
||||||
EnvKeyBaseURL,
|
EnvKeyBaseURL,
|
||||||
@@ -136,13 +133,11 @@ func GenerateEnvFile(rootPath string, overwrite bool) error {
|
|||||||
|
|
||||||
// Define default values and comments for specific keys
|
// Define default values and comments for specific keys
|
||||||
defaults := map[string]string{
|
defaults := map[string]string{
|
||||||
EnvKeyRepositoryType: "postgres",
|
EnvKeyIsLocal: "true",
|
||||||
EnvKeyIsLocal: "false",
|
EnvKeyIsDev: "true",
|
||||||
EnvKeyIsDev: "false",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
comments := map[string]string{
|
comments := map[string]string{
|
||||||
EnvKeyRepositoryType: "# Repository type (postgres, sqlite, etc.)",
|
|
||||||
EnvKeyDatabaseURL: "# Database connection URL",
|
EnvKeyDatabaseURL: "# Database connection URL",
|
||||||
EnvKeySessionSecret: "# Secret key for session management",
|
EnvKeySessionSecret: "# Secret key for session management",
|
||||||
EnvKeyBaseURL: "# Base URL of the application",
|
EnvKeyBaseURL: "# Base URL of the application",
|
||||||
|
|||||||
+2
-9
@@ -12,15 +12,8 @@ func main() {
|
|||||||
GlobalI18n = GlobalI18nImplementation{}
|
GlobalI18n = GlobalI18nImplementation{}
|
||||||
|
|
||||||
environment := env.LoadEnvironment()
|
environment := env.LoadEnvironment()
|
||||||
|
Debug(environment)
|
||||||
db, err := CreatePostgresConnpool(environment.DatabaseUrl)
|
|
||||||
if err != nil {
|
|
||||||
Error("Failed to create database connection:", err)
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer db.Close()
|
|
||||||
|
|
||||||
Debug("starting white label app on port 8090")
|
Debug("starting white label app on port 8090")
|
||||||
handler := routes.CreateApi(db)
|
handler := routes.CreateApi()
|
||||||
log.Fatal(http.ListenAndServe(":8090", handler))
|
log.Fatal(http.ListenAndServe(":8090", handler))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,11 @@ import (
|
|||||||
"ersteller-lib/starter/page"
|
"ersteller-lib/starter/page"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
|
||||||
. "maragu.dev/gomponents"
|
. "maragu.dev/gomponents"
|
||||||
. "maragu.dev/gomponents/html"
|
. "maragu.dev/gomponents/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateApi(db *pgxpool.Pool) http.Handler {
|
func CreateApi() http.Handler {
|
||||||
server := NewHtmxServer()
|
server := NewHtmxServer()
|
||||||
|
|
||||||
HtmxRouteDebugTrace = true
|
HtmxRouteDebugTrace = true
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ tmp_dir = "tmp"
|
|||||||
bin = "./tmp/main"
|
bin = "./tmp/main"
|
||||||
cmd = "time go build -gcflags=\"all=-l\" -ldflags=\"-w -s\" -o ./tmp/main main.go"
|
cmd = "time go build -gcflags=\"all=-l\" -ldflags=\"-w -s\" -o ./tmp/main main.go"
|
||||||
delay = 1000
|
delay = 1000
|
||||||
exclude_dir = ["assets", "tmp", "vendor", "testdata", "cdk", "dist", "db"]
|
exclude_dir = ["assets", "tmp", "vendor", "testdata", "cdk", "dist", "db", "static"]
|
||||||
exclude_file = []
|
exclude_file = []
|
||||||
exclude_regex = ["_test.go"]
|
exclude_regex = ["_test.go"]
|
||||||
exclude_unchanged = false
|
exclude_unchanged = false
|
||||||
|
|||||||
Reference in New Issue
Block a user