|
16 | 16 |
|
17 | 17 | package constants |
18 | 18 |
|
19 | | -// connection information |
20 | | -const ( |
21 | | - MySQLDefaultDSN = "douyin:douyin123@tcp(127.0.0.1:18000)/douyin?charset=utf8&parseTime=True&loc=Local" |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "os" |
| 22 | +) |
| 23 | + |
| 24 | +// GetMySQLDSN retrieves the MySQL DSN from env, with fatal exit if unset. |
| 25 | +func GetMySQLDSN() string { |
| 26 | + dsn := os.Getenv("DB_DSN") |
| 27 | + if dsn == "" { |
| 28 | + fmt.Fprintf(os.Stderr, "fatal: DB_DSN is not set\n") |
| 29 | + os.Exit(1) |
| 30 | + } |
| 31 | + return dsn |
| 32 | +} |
| 33 | + |
| 34 | +// GetMinioEndpoint retrieves the MinIO endpoint from env, with fatal exit if unset. |
| 35 | +func GetMinioEndpoint() string { |
| 36 | + ep := os.Getenv("MINIO_ENDPOINT") |
| 37 | + if ep == "" { |
| 38 | + fmt.Fprintf(os.Stderr, "fatal: MINIO_ENDPOINT is not set\n") |
| 39 | + os.Exit(1) |
| 40 | + } |
| 41 | + return ep |
| 42 | +} |
22 | 43 |
|
23 | | - MinioEndPoint = "localhost:18001" |
24 | | - MinioAccessKeyID = "douyin" |
25 | | - MinioSecretAccessKey = "douyin123" |
26 | | - MiniouseSSL = false |
| 44 | +// GetMinioAccessKeyID retrieves the MinIO access key from env, with fatal exit if unset. |
| 45 | +func GetMinioAccessKeyID() string { |
| 46 | + key := os.Getenv("MINIO_ACCESS_KEY_ID") |
| 47 | + if key == "" { |
| 48 | + fmt.Fprintf(os.Stderr, "fatal: MINIO_ACCESS_KEY_ID is not set\n") |
| 49 | + os.Exit(1) |
| 50 | + } |
| 51 | + return key |
| 52 | +} |
27 | 53 |
|
28 | | - RedisAddr = "localhost:18003" |
29 | | - RedisPassword = "douyin123" |
| 54 | +// GetMinioSecretAccessKey retrieves the MinIO secret key from env, with fatal exit if unset. |
| 55 | +func GetMinioSecretAccessKey() string { |
| 56 | + key := os.Getenv("MINIO_SECRET_ACCESS_KEY") |
| 57 | + if key == "" { |
| 58 | + fmt.Fprintf(os.Stderr, "fatal: MINIO_SECRET_ACCESS_KEY is not set\n") |
| 59 | + os.Exit(1) |
| 60 | + } |
| 61 | + return key |
| 62 | +} |
| 63 | + |
| 64 | +// GetRedisAddr retrieves the Redis address from env, with fatal exit if unset. |
| 65 | +func GetRedisAddr() string { |
| 66 | + addr := os.Getenv("REDIS_ADDR") |
| 67 | + if addr == "" { |
| 68 | + fmt.Fprintf(os.Stderr, "fatal: REDIS_ADDR is not set\n") |
| 69 | + os.Exit(1) |
| 70 | + } |
| 71 | + return addr |
| 72 | +} |
| 73 | + |
| 74 | +// GetRedisPassword retrieves the Redis password from env, with fatal exit if unset. |
| 75 | +func GetRedisPassword() string { |
| 76 | + return os.Getenv("REDIS_PASSWORD") |
| 77 | +} |
| 78 | + |
| 79 | +// connection information |
| 80 | +const ( |
| 81 | + MiniouseSSL = false |
30 | 82 | ) |
31 | 83 |
|
32 | 84 | // constants in the project |
|
0 commit comments