refactor: HTPASSWD_PATH와 포트 설정을 config.json으로 외부화
Co-authored-by: aider (gemini/gemini-2.5-flash) <aider@aider.chat>
This commit is contained in:
@@ -24,19 +24,42 @@ type AddUserRequest struct {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
// Config는 애플리케이션 설정을 나타냅니다.
|
||||
type Config struct {
|
||||
HtpasswdPath string `json:"htpasswdPath"`
|
||||
Port int `json:"port"`
|
||||
}
|
||||
|
||||
var (
|
||||
htpasswdPath string
|
||||
htpasswdPath string
|
||||
appPort int // 애플리케이션 포트
|
||||
htpasswdMutex sync.Mutex // htpasswd 명령 실행 시 동시성 문제를 방지하기 위한 뮤텍스
|
||||
usernameRegex *regexp.Regexp // 사용자 이름 유효성 검사를 위한 정규식
|
||||
)
|
||||
|
||||
func init() {
|
||||
// HTPASSWD_PATH 환경 변수 설정
|
||||
htpasswdPath = os.Getenv("HTPASSWD_PATH")
|
||||
if htpasswdPath == "" {
|
||||
log.Fatal("환경 변수 HTPASSWD_PATH가 설정되지 않았습니다.")
|
||||
// config.json 파일에서 설정 로드
|
||||
configData, err := os.ReadFile("config.json")
|
||||
if err != nil {
|
||||
log.Fatalf("config.json 파일을 읽을 수 없습니다: %v", err)
|
||||
}
|
||||
|
||||
var cfg Config
|
||||
if err := json.Unmarshal(configData, &cfg); err != nil {
|
||||
log.Fatalf("config.json 파싱 오류: %v", err)
|
||||
}
|
||||
|
||||
htpasswdPath = cfg.HtpasswdPath
|
||||
appPort = cfg.Port
|
||||
|
||||
if htpasswdPath == "" {
|
||||
log.Fatal("config.json에 'htpasswdPath'가 설정되지 않았습니다.")
|
||||
}
|
||||
if appPort == 0 {
|
||||
appPort = 8000 // 기본 포트
|
||||
log.Printf("config.json에 'port'가 설정되지 않아 기본값 %d번 포트를 사용합니다.\n", appPort)
|
||||
}
|
||||
|
||||
// 사용자 이름 유효성 검사 정규식 초기화: 영문, 숫자, 하이픈, 언더스코어만 허용
|
||||
usernameRegex = regexp.MustCompile("^[a-zA-Z0-9_-]+$")
|
||||
}
|
||||
@@ -51,9 +74,9 @@ func main() {
|
||||
mux.HandleFunc("/api/users", handleUsers)
|
||||
mux.HandleFunc("/api/users/", handleDeleteUser) // DELETE 요청 처리
|
||||
|
||||
log.Println("VaultKeeper 서버가 8000 포트에서 시작됩니다.")
|
||||
log.Printf("VaultKeeper 서버가 %d 포트에서 시작됩니다.\n", appPort)
|
||||
log.Printf("HTPASSWD_PATH: %s\n", htpasswdPath)
|
||||
log.Fatal(http.ListenAndServe(":8000", mux))
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", appPort), mux))
|
||||
}
|
||||
|
||||
// serveFrontend는 index.html 파일을 제공합니다.
|
||||
|
||||
Reference in New Issue
Block a user