mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fix: adjust docker and any file for starting project
This commit is contained in:
+70
-62
@@ -1,7 +1,8 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
||||
|
||||
@@ -9,32 +10,28 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
IsProd bool
|
||||
AppHost string
|
||||
Version string
|
||||
LogLevel string
|
||||
AppPort int
|
||||
DBHost string
|
||||
DBUser string
|
||||
DBPassword string
|
||||
DBName string
|
||||
DBPort int
|
||||
JWTSecret string
|
||||
JWTAccessExp int
|
||||
JWTRefreshExp int
|
||||
JWTResetPasswordExp int
|
||||
JWTVerifyEmailExp int
|
||||
PostgresDSN string
|
||||
RedisURL string
|
||||
Issuer string
|
||||
SMTPHost string
|
||||
SMTPPort int
|
||||
SMTPUsername string
|
||||
SMTPPassword string
|
||||
EmailFrom string
|
||||
GoogleClientID string
|
||||
GoogleClientSecret string
|
||||
RedirectURL string
|
||||
IsProd bool
|
||||
AppHost string
|
||||
Version string
|
||||
LogLevel string
|
||||
AppPort int
|
||||
DBHost string
|
||||
DBUser string
|
||||
DBPassword string
|
||||
DBName string
|
||||
DBPort int
|
||||
JWTSecret string
|
||||
JWTAccessExp int
|
||||
JWTRefreshExp int
|
||||
JWTResetPasswordExp int
|
||||
JWTVerifyEmailExp int
|
||||
RedisURL string
|
||||
CORSAllowOrigins []string
|
||||
CORSAllowMethods []string
|
||||
CORSAllowHeaders []string
|
||||
CORSExposeHeaders []string
|
||||
CORSAllowCredentials bool
|
||||
CORSMaxAge int
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -42,16 +39,8 @@ func init() {
|
||||
|
||||
// server configuration
|
||||
IsProd = viper.GetString("APP_ENV") == "prod"
|
||||
// AppHost = viper.GetString("APP_HOST")
|
||||
// AppPort = viper.GetInt("APP_PORT")
|
||||
AppHost = viper.GetString("APP_HOST")
|
||||
if AppHost == "" {
|
||||
AppHost = "0.0.0.0"
|
||||
}
|
||||
AppPort = viper.GetInt("APP_PORT")
|
||||
if AppPort == 0 {
|
||||
AppPort = 8080
|
||||
}
|
||||
Version = viper.GetString("VERSION")
|
||||
LogLevel = viper.GetString("LOG_LEVEL")
|
||||
|
||||
@@ -61,13 +50,6 @@ func init() {
|
||||
DBPassword = viper.GetString("DB_PASSWORD")
|
||||
DBName = viper.GetString("DB_NAME")
|
||||
DBPort = viper.GetInt("DB_PORT")
|
||||
PostgresDSN = viper.GetString("POSTGRES_DSN")
|
||||
if PostgresDSN == "" {
|
||||
PostgresDSN = fmt.Sprintf(
|
||||
"postgres://%s:%s@%s:%d/%s?sslmode=disable",
|
||||
DBUser, DBPassword, DBHost, DBPort, DBName,
|
||||
)
|
||||
}
|
||||
|
||||
// jwt configuration
|
||||
JWTSecret = viper.GetString("JWT_SECRET")
|
||||
@@ -76,27 +58,16 @@ func init() {
|
||||
JWTResetPasswordExp = viper.GetInt("JWT_RESET_PASSWORD_EXP_MINUTES")
|
||||
JWTVerifyEmailExp = viper.GetInt("JWT_VERIFY_EMAIL_EXP_MINUTES")
|
||||
|
||||
// Redis / OIDC
|
||||
RedisURL = viper.GetString("REDIS_URL")
|
||||
if RedisURL == "" {
|
||||
RedisURL = "redis://redis:6379/0"
|
||||
}
|
||||
Issuer = viper.GetString("ISSUER")
|
||||
if Issuer == "" {
|
||||
// fallback ke SSO_ISSUER jika kamu sudah pakai itu sebelumnya
|
||||
Issuer = viper.GetString("SSO_ISSUER")
|
||||
}
|
||||
// SMTP configuration
|
||||
SMTPHost = viper.GetString("SMTP_HOST")
|
||||
SMTPPort = viper.GetInt("SMTP_PORT")
|
||||
SMTPUsername = viper.GetString("SMTP_USERNAME")
|
||||
SMTPPassword = viper.GetString("SMTP_PASSWORD")
|
||||
EmailFrom = viper.GetString("EMAIL_FROM")
|
||||
//Cors
|
||||
CORSAllowOrigins = parseList("CORS_ALLOW_ORIGINS")
|
||||
CORSAllowMethods = parseListWithDefault("CORS_ALLOW_METHODS", "GET,POST,PUT,PATCH,DELETE,OPTIONS")
|
||||
CORSAllowHeaders = parseListWithDefault("CORS_ALLOW_HEADERS", "Content-Type,Authorization,X-Requested-With")
|
||||
CORSExposeHeaders = parseList("CORS_EXPOSE_HEADERS")
|
||||
CORSAllowCredentials = viper.GetBool("CORS_ALLOW_CREDENTIALS")
|
||||
CORSMaxAge = viper.GetInt("CORS_MAX_AGE")
|
||||
|
||||
// oauth2 configuration
|
||||
GoogleClientID = viper.GetString("GOOGLE_CLIENT_ID")
|
||||
GoogleClientSecret = viper.GetString("GOOGLE_CLIENT_SECRET")
|
||||
RedirectURL = viper.GetString("REDIRECT_URL")
|
||||
// Redis
|
||||
RedisURL = viper.GetString("REDIS_URL")
|
||||
}
|
||||
|
||||
func loadConfig() {
|
||||
@@ -109,3 +80,40 @@ func loadConfig() {
|
||||
utils.Log.Warn("No .env file found, using environment variables only")
|
||||
}
|
||||
}
|
||||
|
||||
func parseList(key string) []string {
|
||||
raw := strings.TrimSpace(viper.GetString(key))
|
||||
if raw == "" {
|
||||
return nil
|
||||
}
|
||||
if strings.HasPrefix(raw, "[") {
|
||||
var arr []string
|
||||
if json.Unmarshal([]byte(raw), &arr) == nil {
|
||||
for i := range arr {
|
||||
arr[i] = strings.TrimSpace(arr[i])
|
||||
}
|
||||
return arr
|
||||
}
|
||||
}
|
||||
parts := strings.Split(raw, ",")
|
||||
out := make([]string, 0, len(parts))
|
||||
for _, p := range parts {
|
||||
p = strings.TrimSpace(p)
|
||||
if p != "" {
|
||||
out = append(out, p)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func parseListWithDefault(key, def string) []string {
|
||||
if v := parseList(key); len(v) > 0 {
|
||||
return v
|
||||
}
|
||||
// fallback ke default CSV
|
||||
parts := strings.Split(def, ",")
|
||||
for i := range parts {
|
||||
parts[i] = strings.TrimSpace(parts[i])
|
||||
}
|
||||
return parts
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user