mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-19 01:30:26 +08:00
完善主程序
This commit is contained in:
41
config/cfg.go
Normal file
41
config/cfg.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user