|
4 | 4 | _ "embed"
|
5 | 5 | "fmt"
|
6 | 6 | "os"
|
| 7 | + "strconv" |
7 | 8 |
|
8 | 9 | "github.com/fsnotify/fsnotify"
|
9 | 10 | "github.com/spf13/viper"
|
@@ -72,6 +73,65 @@ func InitConfig() {
|
72 | 73 | Conf.System.RSAPublicBytes = pub
|
73 | 74 | Conf.System.RSAPrivateBytes = priv
|
74 | 75 |
|
| 76 | + // 部分配合通过环境变量加载 |
| 77 | + dbDriver := os.Getenv("DB_DRIVER") |
| 78 | + if dbDriver != "" { |
| 79 | + Conf.Database.Driver = dbDriver |
| 80 | + } |
| 81 | + mysqlHost := os.Getenv("MYSQL_HOST") |
| 82 | + if mysqlHost != "" { |
| 83 | + Conf.Mysql.Host = mysqlHost |
| 84 | + } |
| 85 | + mysqlUsername := os.Getenv("MYSQL_USERNAME") |
| 86 | + if mysqlUsername != "" { |
| 87 | + Conf.Mysql.Username = mysqlUsername |
| 88 | + } |
| 89 | + mysqlPassword := os.Getenv("MYSQL_PASSWORD") |
| 90 | + if mysqlPassword != "" { |
| 91 | + Conf.Mysql.Password = mysqlPassword |
| 92 | + } |
| 93 | + mysqlDatabase := os.Getenv("MYSQL_DATABASE") |
| 94 | + if mysqlDatabase != "" { |
| 95 | + Conf.Mysql.Database = mysqlDatabase |
| 96 | + } |
| 97 | + mysqlPort := os.Getenv("MYSQL_PORT") |
| 98 | + if mysqlPort != "" { |
| 99 | + Conf.Mysql.Port, _ = strconv.Atoi(mysqlPort) |
| 100 | + } |
| 101 | + |
| 102 | + ldapUrl := os.Getenv("LDAP_URL") |
| 103 | + if ldapUrl != "" { |
| 104 | + Conf.Ldap.Url = ldapUrl |
| 105 | + } |
| 106 | + ldapBaseDN := os.Getenv("LDAP_BASE_DN") |
| 107 | + if ldapBaseDN != "" { |
| 108 | + Conf.Ldap.BaseDN = ldapBaseDN |
| 109 | + } |
| 110 | + ldapAdminDN := os.Getenv("LDAP_ADMIN_DN") |
| 111 | + if ldapAdminDN != "" { |
| 112 | + Conf.Ldap.AdminDN = ldapAdminDN |
| 113 | + } |
| 114 | + ldapAdminPass := os.Getenv("LDAP_ADMIN_PASS") |
| 115 | + if ldapAdminPass != "" { |
| 116 | + Conf.Ldap.AdminPass = ldapAdminPass |
| 117 | + } |
| 118 | + ldapUserDN := os.Getenv("LDAP_USER_DN") |
| 119 | + if ldapUserDN != "" { |
| 120 | + Conf.Ldap.UserDN = ldapUserDN |
| 121 | + } |
| 122 | + ldapUserInitPassword := os.Getenv("LDAP_USER_INIT_PASSWORD") |
| 123 | + if ldapUserInitPassword != "" { |
| 124 | + |
| 125 | + Conf.Ldap.UserInitPassword = ldapUserInitPassword |
| 126 | + } |
| 127 | + ldapDefaultEmailSuffix := os.Getenv("LDAP_DEFAULT_EMAIL_SUFFIX") |
| 128 | + if ldapDefaultEmailSuffix != "" { |
| 129 | + Conf.Ldap.DefaultEmailSuffix = ldapDefaultEmailSuffix |
| 130 | + } |
| 131 | + ldapUserPasswordEncryptionType := os.Getenv("LDAP_USER_PASSWORD_ENCRYPTION_TYPE") |
| 132 | + if ldapUserPasswordEncryptionType != "" { |
| 133 | + Conf.Ldap.UserPasswordEncryptionType = ldapUserPasswordEncryptionType |
| 134 | + } |
75 | 135 | }
|
76 | 136 |
|
77 | 137 | type SystemConfig struct {
|
|
0 commit comments