init: Initial commit
This commit is contained in:
37
app/config/config.go
Normal file
37
app/config/config.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// Config represents the proxy configuration
|
||||
type Config struct {
|
||||
Listen struct {
|
||||
Address string `yaml:"address"`
|
||||
Port int `yaml:"port"`
|
||||
} `yaml:"listen"`
|
||||
Mappings []struct {
|
||||
External string `yaml:"external"`
|
||||
Internal string `yaml:"internal"`
|
||||
Port int `yaml:"port"` // Optional, defaults to listen port
|
||||
} `yaml:"mappings"`
|
||||
Debug bool `yaml:"debug"`
|
||||
}
|
||||
|
||||
// loadConfig loads configuration from YAML file
|
||||
func LoadConfig(configPath string) (*Config, error) {
|
||||
data, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read config file: %w", err)
|
||||
}
|
||||
|
||||
var config Config
|
||||
if err := yaml.Unmarshal(data, &config); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse config file: %w", err)
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
Reference in New Issue
Block a user