tsk-21: Disable registration (#27)

Closes #21

Reviewed-on: phoenix/textsender-auth#27
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-11-27 01:01:32 +00:00
committed by phoenix
parent d01fae0775
commit 9f5029dd6e
26 changed files with 178 additions and 66 deletions
+32 -7
View File
@@ -5,7 +5,9 @@ import (
"fmt"
"log"
"os"
"path"
"strconv"
"strings"
"github.com/joho/godotenv"
@@ -13,9 +15,10 @@ import (
)
type Config struct {
DBConnString string
ServerPort string
ResetDB bool
DBConnString string
ServerPort string
ResetDB bool
EnableRegistration bool
}
type ConnectionInfo struct {
@@ -52,16 +55,24 @@ func Load() *Config {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
cwd, _ := os.Getwd()
envPath := path.Join(cwd, "../..", ".env")
if err = godotenv.Load(envPath); err != nil {
prevPath := path.Join(envPath, "../..", ".env")
if err = godotenv.Load(prevPath); err != nil {
log.Fatal("Error loading .env file")
}
}
}
unpackedConnString := UnpackDBConnString()
dbConnString := unpackedConnString.Parse()
return &Config{
DBConnString: dbConnString,
ServerPort: *port,
ResetDB: *resetDb,
DBConnString: dbConnString,
ServerPort: *port,
ResetDB: *resetDb,
EnableRegistration: CheckRegistration(),
}
}
@@ -120,6 +131,20 @@ func UnpackDBConnString() (connInfo ConnectionInfo) {
return
}
func CheckRegistration() bool {
if flagValue := os.Getenv("ENABLE_REGISTRATION"); flagValue != "" {
if val := strings.ToUpper(flagValue); val == "TRUE" {
return true
} else if val == "FALSE" {
return false
} else {
return true
}
} else {
return true
}
}
func (c *Config) GetDBConnString() string {
return c.DBConnString
}