File size: 1,076 Bytes
34fee23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package utils

import (
	"log"
	"os"

	"gopkg.in/ini.v1"
)

type Config struct {
	Server ServerConfig `ini:"server"`
	Client ClientConfig `ini:"client"`
	Proxy  ProxyConfig  `ini:"proxy"`
}

type ServerConfig struct {
	BindAddr      string `ini:"bind_addr"`
	BindPort      int    `ini:"bind_port"`
	PrivateKeyPath string `ini:"private_key_path"`
}

type ClientConfig struct {
	ServerAddr     string `ini:"server_addr"`
	ServerPort     int    `ini:"server_port"`
	PrivateKeyPath string `ini:"private_key_path"`
}

type ProxyConfig struct {
	LocalAddr         string `ini:"local_addr"`
	LocalPort         int    `ini:"local_port"`
	ProxyType         string `ini:"proxy_type"`
	ProxyName         string `ini:"proxy_name"`
	EncryptionEnabled bool   `ini:"encryption_enabled"`
}

func LoadConfig() *Config {
	cfg, err := ini.Load("config.ini")
	if err != nil {
		log.Fatalf("Failed to read config file: %v", err)
		os.Exit(1)
	}
	
	config := &Config{}
	err = cfg.MapTo(config)
	if err != nil {
		log.Fatalf("Failed to parse config file: %v", err)
		os.Exit(1)
	}
	
	return config
}