-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: able to deploy with environment variables (#36)
- Loading branch information
Showing
1 changed file
with
39 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,49 @@ | ||
package conf | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func env(name string, defaultValue string) string { | ||
env := os.Getenv(name) | ||
if env == "" { | ||
return defaultValue | ||
} | ||
return env | ||
} | ||
|
||
func envNum(name string, defaultValue int) int { | ||
env := os.Getenv(name) | ||
if env == "" { | ||
return defaultValue | ||
} | ||
num, err := strconv.Atoi(env) | ||
if err != nil { | ||
return defaultValue | ||
} | ||
return num | ||
} | ||
|
||
var SystemConfig = &system{ | ||
Listen: ":8080", | ||
Debug: true, | ||
Listen: env("LISTEN", ":8080"), | ||
Debug: env("DEBUG", "false") == "true", | ||
} | ||
|
||
var DataSourceConfig = &datasource{ | ||
Driver: "sqlite3", | ||
Host: "localhost", | ||
Port: 3306, | ||
Database: "leziapi", | ||
Username: "root", | ||
Password: "root", | ||
File: "leziapi.db", | ||
Prefix: "lezi_", | ||
Driver: env("DB_DRIVER", "sqlite3"), | ||
Host: env("DB_HOST", "localhost"), | ||
Port: envNum("DB_PORT", 3306), | ||
Database: env("DB_DATABASE", "leziapi"), | ||
Username: env("DB_USERNAME", "root"), | ||
Password: env("DB_PASSWORD", "root"), | ||
File: env("DB_FILE", "leziapi.db"), | ||
Prefix: env("DB_PREFIX", "lezi_"), | ||
} | ||
|
||
var RedisConfig = &redis{ | ||
Network: "tcp", | ||
Server: "", | ||
Password: "", | ||
DB: 0, | ||
Network: env("REDIS_NETWORK", "tcp"), | ||
Server: env("REDIS_SERVER", ""), | ||
Password: env("REDIS_PASSWORD", ""), | ||
DB: envNum("REDIS_DB", 0), | ||
} |