1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-19 01:30:26 +08:00

完善主程序

This commit is contained in:
fumiama
2021-12-28 21:50:10 +08:00
parent f0956ae742
commit 6ae8e88bd1
18 changed files with 499 additions and 14 deletions

41
config/cfg.go Normal file
View File

@@ -0,0 +1,41 @@
package config
import (
"bytes"
"log"
"os"
"gopkg.in/yaml.v3"
)
// Config WireGold 配置文件
type Config struct {
IP string `yaml:"IP"`
SubNet string `yaml:"SubNet"`
PrivateKey string `yaml:"PrivateKey"`
EndPoint string `yaml:"EndPoint"`
Peers []Peer `yaml:"Peers"`
}
// Peer 对端信息
type Peer struct {
IP string `yaml:"IP"`
SubNet string `yaml:"SubNet"`
PublicKey string `yaml:"PublicKey"`
EndPoint string `yaml:"EndPoint"`
AllowedIPs []string `yaml:"AllowedIPs"`
KeepAliveSeconds int64 `yaml:"KeepAliveSeconds"`
AllowTrans bool `yaml:"AllowTrans"`
}
func Parse(path string) (c Config) {
file, err := os.ReadFile(path)
if err != nil {
log.Fatal("open config file failed:", err)
}
err = yaml.NewDecoder(bytes.NewReader(file)).Decode(&c)
if err != nil {
log.Fatal("invalid config file:", err)
}
return
}