package main
import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"gopkg.in/yaml.v2"
)
//目录文件
var (
cfgFile = "./config.yml"
)
type proxies struct {
Name string `yaml:"name,omitempty",json:"name,omitempty"`
Type string `yaml:"type,omitempty",json:"type,omitempty"`
Server string `yaml:"server,omitempty",json:"server,omitempty"`
Port string `yaml:"port,omitempty",json:"port,omitempty"`
Cipher string `yaml:"cipher,omitempty",json:"cipher,omitempty"`
Password string `yaml:"password,omitempty",json:"password,omitempty"`
Udp string `yaml:"udp,omitempty",json:"udp,omitempty"`
}
type conf struct {
Proxies []proxies `yaml:"proxies",json:"proxies"`
}
func (c *conf) getConf() *conf {
yamlFile, err := ioutil.ReadFile(cfgFile)
if err != nil {
fmt.Println(err.Error())
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
fmt.Println(err.Error())
}
return c
}
func main() {
var c conf
conf := c.getConf()
//proxie to json
jsonProxie, _ := json.Marshal(conf.Proxies)
fmt.Println(string(jsonProxie))
}