Dockerfile and some add/fix config

This commit is contained in:
dalbodeule
2025-10-14 21:21:12 +09:00
parent e261ec59a1
commit bc3cd19b24
6 changed files with 72 additions and 30 deletions

View File

@@ -1,7 +1,6 @@
package utils
import (
"log"
"os"
"strings"
@@ -13,23 +12,23 @@ type Config struct {
Geoip string
CountryBlacklist []string
PgDsn string
RootPath string
}
func GetConfig() *Config {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
_ = godotenv.Load()
port := os.Getenv("PORT")
geoipDbfile := os.Getenv("GEOIP_DB")
countryBlacklist := os.Getenv("COUNTRY_BLACKLIST")
pgDsn := os.Getenv("DB_DSN")
rootPath := os.Getenv("ROOT_PATH")
return &Config{
Port: port,
Geoip: geoipDbfile,
CountryBlacklist: strings.Split(countryBlacklist, ","),
PgDsn: pgDsn,
RootPath: rootPath,
}
}

View File

@@ -30,10 +30,7 @@ func GetIPInfo(ip string, db *geoip2.Reader) *IpInfo {
country := func(ip net.IP) string {
country, _ := db.Country(parsedIp)
println(country.Country.IsoCode)
if country != nil && country.Country.IsoCode != "" {
println(country.Country.IsoCode)
return country.Country.IsoCode
} else {
return "ZZ"

View File

@@ -15,8 +15,8 @@ import (
// GenerateHostKey는 'keys' 디렉토리를 생성하고, RSA, ECDSA, Ed25519 호스트 개인 키를 생성하여 저장합니다.
// 개인 키는 OpenSSH 형식으로 암호화되어 저장됩니다.
func GenerateHostKey() error {
const keyDir = "./keys"
func GenerateHostKey(rootPath string) error {
keyDir := rootPath + "/keys"
// 1. 키 디렉토리 생성
if err := os.MkdirAll(keyDir, 0700); err != nil {
@@ -103,25 +103,27 @@ func generateAndSaveKey(path string, keyType string) error {
return nil
}
func CheckHostKey() ([]ssh.Signer, error) {
keyFiles := []string{"./keys/id_rsa", "./keys/id_ecdsa", "./keys/id_ed25519"}
func CheckHostKey(rootPath string) ([]ssh.Signer, error) {
keyFiles := []string{"keys/id_rsa", "keys/id_ecdsa", "keys/id_ed25519"}
for _, keyFile := range keyFiles {
if _, err := os.Stat(keyFile); os.IsNotExist(err) {
return nil, fmt.Errorf("key file %s does not exist", keyFile)
tmp := rootPath + "/" + keyFile
if _, err := os.Stat(tmp); os.IsNotExist(err) {
return nil, fmt.Errorf("key file %s does not exist", tmp)
}
}
var keys = make([]ssh.Signer, 0)
for _, keyFile := range keyFiles {
keyBytes, err := os.ReadFile(keyFile)
tmp := rootPath + "/" + keyFile
keyBytes, err := os.ReadFile(tmp)
if err != nil {
return nil, fmt.Errorf("failed to read key file %s: %v", keyFile, err)
return nil, fmt.Errorf("failed to read key file %s: %v", tmp, err)
}
signer, err := ssh.ParsePrivateKey(keyBytes)
if err != nil {
return nil, fmt.Errorf("failed to parse private key %s: %v", keyFile, err)
return nil, fmt.Errorf("failed to parse private key %s: %v", tmp, err)
}
keys = append(keys, signer)