config.go

package main

import (
    "io/ioutil"

    "github.com/go-yaml/yaml"
)

// 代理配置数据结构
type ProxyConfig struct {
    Bind         string    `yaml:"bind"`  //前置服务器地址
    WaitQueueLen int       `yaml:"wait_queue_len"` //等待队列大小
    MaxConn      int       `yaml:"max_conn"`  // 最大连接数
    Timeout      int       `yaml:"timeout"`  //连接超时时间
    FailOver     int       `yaml:"failover"`  //失败重试次数
    Backend      []string  `yaml:"backend"`  //被代理服务器 列表
    Log          LogConfig `yaml:"log"`  //日志配置
    Stats        string    `yaml:"stats"`  //监控服务地址   用来查看服务器状态
}

// 日志配置结构信息
type LogConfig struct {
    Level string `yaml:"level"`  //  日志级别
    Path  string `yaml:"path"`  //  日志存放地址
}

// 解析配置文件
func parseConfigFile(filePath string) error {
    if conf, err := ioutil.ReadFile(filePath); err == nil {  // 读取配置文件
        if err = yaml.Unmarshal(conf, &Config); err != nil {  //解析toml文件内容到  Config中
            return err
        }
    } else {
        return err
    }
    return nil
}
原文地址:https://www.cnblogs.com/zhangboyu/p/7456713.html