Skip to content

Commit

Permalink
Chore: able to deploy with environment variables (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
AH-dark authored Sep 12, 2022
1 parent 549a443 commit ef49f22
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions pkg/conf/data.go
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),
}

0 comments on commit ef49f22

Please sign in to comment.